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

// next-intl mocked to echo keys; locale = en so money/date format with ASCII digits we can assert on.
jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
  useLocale: () => 'en',
}));

import BookingRequestSummaryCard, { BookingRequestSummaryCardProps } from './BookingRequestSummaryCard';

const BASE: BookingRequestSummaryCardProps = {
  nurseName: 'Maryam Rezaei',
  nurseAvatarUrl: null,
  nurseRating: 4.8,
  patientName: 'Haj Mousavi',
  variantLabel: 'Elderly care — day shift',
  variantPrice: '2800000',
  variantPriceUnit: 'per_hour',
  addressLabel: 'Home · Tehran · Saadat Abad',
  requestedDate: '2026-08-01',
  requestedTimeStart: '09:00:00',
  requestedTimeEnd: '13:00:00',
};

function renderCard(props: Partial<BookingRequestSummaryCardProps> = {}) {
  return render(
    <ThemeProvider>
      <BookingRequestSummaryCard {...BASE} {...props} />
    </ThemeProvider>,
  );
}

describe('<BookingRequestSummaryCard/> component', () => {
  it('renders the nurse, patient, service and address', () => {
    renderCard();
    expect(screen.getByText('Maryam Rezaei')).toBeInTheDocument();
    expect(screen.getByText('Haj Mousavi')).toBeInTheDocument();
    expect(screen.getByText('Elderly care — day shift')).toBeInTheDocument();
    expect(screen.getByText('Home · Tehran · Saadat Abad')).toBeInTheDocument();
  });

  it('prices the service in grouped Toman when a variantPrice is present', () => {
    renderCard();
    // 2,800,000 IRR = 280,000 Toman.
    expect(screen.getByText(/280,000/)).toBeInTheDocument();
  });

  it('hides the price line when variantPrice is null (real-path contract gap)', () => {
    renderCard({ variantPrice: null });
    expect(screen.queryByText(/280,000/)).not.toBeInTheDocument();
  });

  it('hides the rating row when no rating is supplied', () => {
    renderCard({ nurseRating: null });
    expect(screen.queryByText('4.8')).not.toBeInTheDocument();
  });
});
