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 | Record<string, unknown>) => {
      if (typeof fallback === 'string') {
        return fallback;
      }
      if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
        return fallback.defaultValue;
      }
      return key;
    },
  }),
}));

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

vi.mock('@/actions/App/Http/Controllers/Auth/PasswordResetLinkController', () => ({
  store: {
    form: () => ({}),
  },
}));

vi.mock('@inertiajs/react', () => ({
  Form: ({ children }: { children: (props: { processing: boolean; errors: Record<string, string[]> }) => React.ReactNode }) => (
    <form>{children({ processing: false, errors: {} })}</form>
  ),
  Head: () => null,
}));

vi.mock('@/routes', () => ({
  login: () => '/login',
}));

vi.mock('@/components/input-error', () => ({
  default: () => null,
}));

vi.mock('@/components/text-link', () => ({
  default: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
}));

vi.mock('@/components/ui/button', () => ({
  Button: ({ children }: { children: React.ReactNode }) => <button>{children}</button>,
}));

vi.mock('@/components/ui/input', () => ({
  Input: (props: React.InputHTMLAttributes<HTMLInputElement>) => <input {...props} />,
}));

vi.mock('@/components/ui/label', () => ({
  Label: ({ children }: { children: React.ReactNode }) => <label>{children}</label>,
}));

import ForgotPassword from '../forgot-password';

describe('ForgotPassword', () => {
  it('renders the translated copy', () => {
    render(<ForgotPassword />);

    expect(screen.getByText('Forgot password')).toBeInTheDocument();
    expect(screen.getByText('Enter your email to receive a password reset link')).toBeInTheDocument();
    expect(screen.getByText('Email password reset link')).toBeInTheDocument();
    expect(screen.getByText('Or, return to')).toBeInTheDocument();
    expect(screen.getByText('Login')).toBeInTheDocument();
  });
});
