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

vi.mock('react-router-dom', () => ({
  useParams: () => ({ taskId: '12' }),
  useNavigate: () => vi.fn(),
}));

vi.mock('@tamagui/stacks', () => ({
  YStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
  XStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('@tamagui/text', () => ({
  SizableText: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
}));

vi.mock('@tamagui/button', () => ({
  Button: ({ children, ...rest }: { children: React.ReactNode }) => (
    <button type="button" {...rest}>
      {children}
    </button>
  ),
}));

vi.mock('../components/AppShell', () => ({
  default: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('../components/SurfaceCard', () => ({
  default: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

vi.mock('../services/tasksApi', () => ({
  fetchTasks: () => Promise.resolve([{ id: 12, title: 'Capture the dancefloor', description: 'Find the happiest crew.' }]),
}));

vi.mock('@/guest/i18n/useTranslation', () => ({
  useTranslation: () => ({ t: (_key: string, fallback?: string) => fallback ?? _key, locale: 'de' }),
}));

vi.mock('@/hooks/use-appearance', () => ({
  useAppearance: () => ({ resolved: 'light' }),
}));

import TaskDetailScreen from '../screens/TaskDetailScreen';

describe('TaskDetailScreen', () => {
  it('renders task title', async () => {
    render(
      <EventDataProvider token="token">
        <TaskDetailScreen />
      </EventDataProvider>
    );

    expect(await screen.findByText('Capture the dancefloor')).toBeInTheDocument();
  });

  it('shows disabled state when tasks are disabled', () => {
    render(
      <EventDataProvider token="token" tasksEnabledFallback={false}>
        <TaskDetailScreen />
      </EventDataProvider>
    );

    expect(screen.getByText('Tasks are disabled')).toBeInTheDocument();
  });
});
