import React from 'react';
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { ContactFormPage } from '@/pages/ContactForm';

vi.mock('@/api/hooks', () => ({
  useContact: () => ({ data: undefined, isLoading: false }),
  useCreateContact: () => ({ mutateAsync: vi.fn(), isPending: false }),
  useUpdateContact: () => ({ mutateAsync: vi.fn(), isPending: false }),
  useCompanies: () => ({ data: { items: [{ id: '1', name: 'TestCorp GmbH' }], total: 1 }, isLoading: false }),
}));

vi.mock('@/components/ui/Toast', () => ({
  useToast: () => ({ success: vi.fn(), error: vi.fn(), info: vi.fn() }),
}));

vi.mock('@/components/shared/UnsavedChangesGuard', () => ({
  UnsavedChangesGuard: () => null,
}));

describe('ContactFormPage', () => {
  it('renders form with first name field', () => {
    render(<MemoryRouter><ContactFormPage /></MemoryRouter>);
    expect(screen.getByLabelText(/Vorname/)).toBeInTheDocument();
  });

  it('renders form with last name field', () => {
    render(<MemoryRouter><ContactFormPage /></MemoryRouter>);
    expect(screen.getByLabelText(/Nachname/)).toBeInTheDocument();
  });

  it('renders email field', () => {
    render(<MemoryRouter><ContactFormPage /></MemoryRouter>);
    expect(screen.getByLabelText(/E-Mail/)).toBeInTheDocument();
  });
});
