import { render, screen } from '@testing-library/react';
import { ThemeProvider } from '../../../theme';

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
  useLocale: () => 'en',
}));

import CareInstructionsCard from './CareInstructionsCard';
import type { CareInstructionsDto } from '@/services/bookings/types';

const FULL: CareInstructionsDto = {
  bookingId: 5001,
  currentConditions: 'Type 2 diabetes, hypertension',
  medications: 'Metformin 500 · Losartan 25',
  allergies: 'Penicillin',
  specialInstructions: 'Check blood sugar before meals.',
  emergencyContactName: 'Zahra Mousavi',
  emergencyContactPhone: '09121234567',
};

function renderCard(data: CareInstructionsDto) {
  return render(
    <ThemeProvider>
      <CareInstructionsCard data={data} />
    </ThemeProvider>,
  );
}

describe('<CareInstructionsCard/> component', () => {
  it('renders every decrypted clinical field', () => {
    renderCard(FULL);
    expect(screen.getByText('Type 2 diabetes, hypertension')).toBeInTheDocument();
    expect(screen.getByText('Metformin 500 · Losartan 25')).toBeInTheDocument();
    expect(screen.getByText('Penicillin')).toBeInTheDocument();
    expect(screen.getByText('Check blood sugar before meals.')).toBeInTheDocument();
    expect(screen.getByText('Zahra Mousavi · 09121234567')).toBeInTheDocument();
  });

  it('shows the "not recorded" placeholder for a null field', () => {
    renderCard({ ...FULL, allergies: null });
    expect(screen.getByText('care_none')).toBeInTheDocument();
  });

  it('shows the empty state when nothing was recorded', () => {
    renderCard({
      bookingId: 5001,
      currentConditions: null,
      medications: null,
      allergies: null,
      specialInstructions: null,
      emergencyContactName: null,
      emergencyContactPhone: null,
    });
    expect(screen.getByText('care_empty')).toBeInTheDocument();
  });
});
