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

const vuetify = createVuetify();
const baseProps = {
    searchPhone: '',
    filterStatus: null,
    filterProject: null,
    filterCity: null,
    leadStatuses: [{ slug: 'new', nameRu: 'Новые', isSystem: true, sortOrder: 1, colorHex: '#000' }],
    availableProjects: [{ id: 1, name: 'Окна' }],
    availableCities: [] as string[],
};

describe('DealsFilters', () => {
    it('рендерит поле поиска по телефону', () => {
        const w = mount(DealsFilters, { props: baseProps, global: { plugins: [vuetify] } });
        expect(w.find('[data-testid="filter-search-phone"]').exists()).toBe(true);
    });

    it('эмитит update:searchPhone при вводе', async () => {
        const w = mount(DealsFilters, { props: baseProps, global: { plugins: [vuetify] } });
        await w.find('[data-testid="filter-search-phone"] input').setValue('999');
        expect(w.emitted('update:searchPhone')?.at(-1)).toEqual(['999']);
    });

    it('город-селект disabled при пустом availableCities', () => {
        const w = mount(DealsFilters, { props: baseProps, global: { plugins: [vuetify] } });
        expect(w.find('[data-testid="filter-city"]').classes()).toContain('v-input--disabled');
    });

    it('кнопка сброса видна когда есть активный фильтр', () => {
        const w = mount(DealsFilters, {
            props: { ...baseProps, filterStatus: 'new' },
            global: { plugins: [vuetify] },
        });
        expect(w.find('[data-testid="clear-filters-btn"]').exists()).toBe(true);
    });
});
