import React from 'react';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';

vi.mock('react-i18next', () => ({
  useTranslation: () => ({
    t: (key: string, fallback?: string | { defaultValue?: unknown }) => {
      if (key === 'demo_page') {
        return {
          title: 'Demo Page',
          subtitle: 'Subtitle',
          primaryCta: 'Primary',
          secondaryCta: 'Secondary',
          iframeNote: 'Note',
          openFull: 'Open',
          features: [],
        };
      }
      if (typeof fallback === 'string') {
        return fallback;
      }
      if (fallback && typeof fallback === 'object' && 'defaultValue' in fallback) {
        return fallback.defaultValue;
      }
      return key;
    },
  }),
}));

vi.mock('@inertiajs/react', () => ({
  Head: () => null,
  Link: ({ children, href }: { children: React.ReactNode; href: string }) => <a href={href}>{children}</a>,
}));

vi.mock('@/layouts/mainWebsite', () => ({
  default: ({ children, title }: { children: React.ReactNode; title: string }) => (
    <div>
      <h1>{title}</h1>
      {children}
    </div>
  ),
}));

vi.mock('@/hooks/useLocalizedRoutes', () => ({
  useLocalizedRoutes: () => ({
    localizedPath: (path: string) => path,
  }),
}));

vi.mock('@/hooks/useLocale', () => ({
  useLocale: () => 'de',
}));

vi.mock('@/components/ui/dialog', () => ({
  Dialog: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  DialogContent: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

import DemoPage from '../Demo';

describe('DemoPage', () => {
  it('renders the demo headline', () => {
    render(<DemoPage demoToken="demo" />);

    expect(screen.getAllByText('Demo Page').length).toBeGreaterThan(0);
  });
});
