import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import ProjectCard from '../../resources/js/components/projects/ProjectCard.vue';

const vuetify = createVuetify();
const baseProject = {
    id: 1,
    name: 'Окна СПб',
    signal_type: 'site' as const,
    signal_identifier: 'okna.ru',
    daily_limit_target: 50,
    delivered_today: 32,
    is_active: true,
    sync_status: 'ok' as const,
};

describe('ProjectCard', () => {
    it('renders project name + signal_identifier', () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: baseProject, selected: false },
        });
        expect(wrapper.text()).toContain('Окна СПб');
        expect(wrapper.text()).toContain('okna.ru');
    });

    it('shows progress percentage 32/50', () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: baseProject, selected: false },
        });
        expect(wrapper.text()).toMatch(/32.*50/);
    });

    it('emits select event on checkbox change', async () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: baseProject, selected: false },
        });
        await wrapper.find('[data-testid="card-select"] input').trigger('change');
        expect(wrapper.emitted('toggle-select')).toBeTruthy();
    });

    it('shows "На паузе" when is_active=false', () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: { ...baseProject, is_active: false }, selected: false },
        });
        expect(wrapper.text()).toContain('На паузе');
    });

    it('shows balance-blocked label when balance_blocked=true', () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: { ...baseProject, balance_blocked: true }, selected: false },
        });
        expect(wrapper.text()).toContain('не хватает баланса');
    });

    it('does not show balance-blocked label for a normal project', () => {
        const wrapper = mount(ProjectCard, {
            global: { plugins: [vuetify] },
            props: { project: baseProject, selected: false },
        });
        expect(wrapper.text()).not.toContain('не хватает баланса');
    });
});
