import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import { createVuetify } from 'vuetify';
import { createPinia, setActivePinia } from 'pinia';
import DealDetailDrawer from '../../resources/js/components/deals/DealDetailDrawer.vue';
import type { MockDeal } from '../../resources/js/composables/mockDeals';

const vuetify = createVuetify();
const deal: MockDeal = {
    id: 1,
    name: '+7 999',
    phone: '+7 999',
    statusSlug: 'new',
    project: 'Окна',
    manager: { initials: 'AD', name: 'Admin' },
    cost: 0,
    receivedMinutesAgo: 5,
};

function mountDrawer(props: Record<string, unknown>) {
    const pinia = createPinia();
    setActivePinia(pinia);
    return mount(DealDetailDrawer, {
        props: { open: true, deal, ...props },
        global: {
            plugins: [vuetify, pinia],
            stubs: {
                DealDetailBody: true,
                VNavigationDrawer: {
                    template: '<div class="drawer-stub" v-if="modelValue"><slot /></div>',
                    props: ['modelValue'],
                },
            },
        },
    });
}

describe('DealDetailDrawer wrapper', () => {
    it('inline=true рендерит <aside> (master-detail панель)', () => {
        const w = mountDrawer({ inline: true });
        expect(w.find('aside.deal-detail-inline').exists()).toBe(true);
    });

    it('inline=false (по умолчанию) рендерит overlay v-navigation-drawer', () => {
        const w = mountDrawer({});
        expect(w.find('aside.deal-detail-inline').exists()).toBe(false);
    });

    it('inline-панель содержит DealDetailBody', () => {
        const w = mountDrawer({ inline: true });
        expect(w.findComponent({ name: 'DealDetailBody' }).exists()).toBe(true);
    });
});
