import { mount } from '@vue/test-utils';
import { defineComponent } from 'vue';
import { describe, expect, it, vi } from 'vitest';

vi.mock('@inertiajs/vue3', async (importOriginal) => {
    const actual = await importOriginal<typeof import('@inertiajs/vue3')>();

    return {
        ...actual,
        Head: defineComponent({
            props: { title: String },
            template: '<span data-head />',
        }),
    };
});

import RayDocsShow from '@/Pages/Imports/RayDocsShow.vue';

describe('RayDocsShow', () => {
    it('renders the review workspace with an extracted call and PDF preview', () => {
        const wrapper = mount(RayDocsShow, {
            props: {
                rayDocImport: {
                    filename: 'Capital call.pdf',
                    status: 'Completed',
                    statusVariant: 'positive',
                    source: 'Manual upload',
                    fileSize: '120 KB',
                    storageDisk: 'local',
                    storagePath: 'raydocs/imports/call.pdf',
                    mimeType: 'application/pdf',
                    sha256: 'abc123',
                    uploadedBy: 'Reviewer',
                    receivedAt: '2026-07-26 10:00',
                    createdAt: '2026-07-26 10:00:00',
                    updatedAt: '2026-07-26 10:00:00',
                    fileExists: true,
                    metadata: {},
                },
                jobs: [],
                review: {
                    state: 'ready',
                    approvalStatus: 'pending',
                    rejectionReason: null,
                    approvedRecordUrl: null,
                    normalized: {
                        document_type: 'call',
                        fund_name: 'Demo Fund',
                        investor_name: 'Demo Investor',
                        due_date: '2026-08-01',
                        call_amount: '44000',
                        distribution_amount: null,
                        currency: 'EUR',
                    },
                    fund: { id: 'fund-1', name: 'Demo Fund' },
                    investor: { id: 'investor-1', name: 'Demo Investor' },
                    controls: [{
                        code: 'Duplicate check',
                        status: 'Passed',
                        variant: 'positive',
                        message: 'No matching call was found.',
                    }],
                },
                completedExtraction: { resultId: 'result-1', data: { notice: 'Capital call' } },
                fundOptions: [{ id: 'fund-1', name: 'Demo Fund' }],
                investorOptions: [{ id: 'investor-1', name: 'Demo Investor' }],
                actions: {
                    back: '/imports/raydocs',
                    send: '/imports/raydocs/import-1/send',
                    document: '/imports/raydocs/import-1/document',
                    resolve: '/imports/raydocs/import-1/review/resolve',
                    approve: '/imports/raydocs/import-1/review/approve',
                    reject: '/imports/raydocs/import-1/review/reject',
                },
            },
        });

        expect(wrapper.get('h2').text()).toBe('Capital call.pdf');
        expect(wrapper.get('h3').text()).toBe('Stored document');
        expect(wrapper.text()).toContain('Raydocs review');
        expect(wrapper.get('iframe').attributes('src')).toBe('/imports/raydocs/import-1/document');
    });
});
