/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import Illustrations from '../Illustrations';

vi.mock('@inertiajs/react', () => ({
    Head: ({ title }: { title: string }) => <title>{title}</title>,
    Link: ({ href, children, ...rest }: any) => (
        <a href={href} {...rest}>
            {children}
        </a>
    ),
    router: {
        get: vi.fn(),
        post: vi.fn(),
        put: vi.fn(),
        patch: vi.fn(),
        delete: vi.fn(),
        visit: vi.fn(),
    },
    usePage: vi.fn(() => ({
        props: {
            auth: { user: null },
            flash: {},
            errors: {},
            ziggy: {
                url: 'http://localhost',
                port: null,
                defaults: [],
                routes: {},
            },
        },
    })),
    useForm: vi.fn(() => ({
        data: {},
        setData: vi.fn(),
        post: vi.fn(),
        processing: false,
        errors: {},
        reset: vi.fn(),
    })),
}));

vi.mock('@/Layouts/PlatformLayout', () => ({
    default: ({ children }: any) => (
        <div data-testid="platform-layout">{children}</div>
    ),
}));

vi.mock('@/components/illustrations', () => ({
    LoanCycleIllustration: ({ className }: any) => (
        <svg data-testid="loan-cycle-illus" className={className} />
    ),
    DatabaseIsolationIllustration: ({ className }: any) => (
        <svg data-testid="db-isolation-illus" className={className} />
    ),
    EastAfricaMapIllustration: ({ className }: any) => (
        <svg data-testid="east-africa-illus" className={className} />
    ),
    OnboardingFlowIllustration: ({ className }: any) => (
        <svg data-testid="onboarding-illus" className={className} />
    ),
    IsometricLoanIllustration: ({ className }: any) => (
        <svg data-testid="isometric-illus" className={className} />
    ),
}));

vi.mock('framer-motion', () => ({
    motion: {
        div: ({ children, ...rest }: any) => <div {...rest}>{children}</div>,
    },
    AnimatePresence: ({ children }: any) => <>{children}</>,
}));

vi.stubGlobal('route', (name: string) => `/${name}`);

describe('Illustrations showcase page', () => {
    it('renders inside PlatformLayout', () => {
        render(<Illustrations />);
        expect(screen.getByTestId('platform-layout')).toBeInTheDocument();
    });

    it('renders the "Illustration Showcase" heading', () => {
        render(<Illustrations />);
        expect(
            screen.getByRole('heading', { name: 'Illustration Showcase' }),
        ).toBeInTheDocument();
    });

    it('renders illustration name cards', () => {
        render(<Illustrations />);
        expect(screen.getByText('Loan Lifecycle')).toBeInTheDocument();
        expect(screen.getByText('Database Isolation')).toBeInTheDocument();
        expect(screen.getByText('East Africa Network')).toBeInTheDocument();
    });

    it('renders all five illustration components', () => {
        render(<Illustrations />);
        expect(screen.getByTestId('loan-cycle-illus')).toBeInTheDocument();
        expect(screen.getByTestId('db-isolation-illus')).toBeInTheDocument();
        expect(screen.getByTestId('east-africa-illus')).toBeInTheDocument();
        expect(screen.getByTestId('onboarding-illus')).toBeInTheDocument();
        expect(screen.getByTestId('isometric-illus')).toBeInTheDocument();
    });

    it('renders the "Back to home" navigation link', () => {
        render(<Illustrations />);
        expect(screen.getByText('Back to home')).toBeInTheDocument();
    });
});
