import { describe, it, expect, beforeEach } from 'vitest';
import { mount, flushPromises } from '@vue/test-utils';
import { createPinia, setActivePinia } from 'pinia';
import { createVuetify } from 'vuetify';
import { createMemoryHistory, createRouter } from 'vue-router';
import KanbanView from '../../resources/js/views/KanbanView.vue';
import { MOCK_DEALS } from '../../resources/js/composables/mockDeals';

// KanbanView содержит DealDetailDrawer (VNavigationDrawer) — требует
// injected layout от v-app, недоступной в Vitest. Stub'им как в KanbanView.spec.ts.
function setup() {
    setActivePinia(createPinia());
    const router = createRouter({
        history: createMemoryHistory(),
        routes: [{ path: '/', component: KanbanView }],
    });
    router.push('/');
    return mount(KanbanView, {
        global: {
            plugins: [router, createVuetify()],
            stubs: { RouterLink: true, DealDetailDrawer: true, NewDealDialog: true },
        },
    });
}

describe('KanbanView — redesigned', () => {
    beforeEach(() => setActivePinia(createPinia()));

    it('card containers have ld-hover-lift class', async () => {
        const w = setup();
        await flushPromises();
        // Засеваем dealsByStatus (после I3 init пустой — карточек нет)
        const vm = w.vm as unknown as { dealsByStatus: Record<string, unknown[]> };
        for (const d of MOCK_DEALS) {
            (vm.dealsByStatus[d.statusSlug] ??= []).push({ ...d, manager: { ...d.manager } });
        }
        await flushPromises();
        expect(w.html()).toMatch(/ld-hover-lift/);
    });

    it('column headers use ld-label class', async () => {
        const w = setup();
        await flushPromises();
        expect(w.html()).toMatch(/ld-label/);
    });
});
