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

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

import BookingMoneySummary from './BookingMoneySummary';

function renderSummary(viewerRole: 'customer' | 'nurse') {
  return render(
    <ThemeProvider>
      <BookingMoneySummary
        grossPriceIrr="45000000"
        balinyaarCommissionIrr="5400000"
        nursePayoutAmount="39600000"
        viewerRole={viewerRole}
      />
    </ThemeProvider>,
  );
}

describe('<BookingMoneySummary/> component', () => {
  it('renders the three amounts as grouped Toman (IRR ÷ 10), never re-summed', () => {
    renderSummary('customer');
    expect(screen.getByText(/4,500,000/)).toBeInTheDocument(); // gross
    expect(screen.getByText(/540,000/)).toBeInTheDocument(); // commission
    expect(screen.getByText(/3,960,000/)).toBeInTheDocument(); // payout
  });

  it('labels the payout row for the customer', () => {
    renderSummary('customer');
    expect(screen.getByText('money_payout')).toBeInTheDocument();
    expect(screen.queryByText('money_nurse_earning')).not.toBeInTheDocument();
  });

  it('labels the payout row as the nurse earning in the nurse view', () => {
    renderSummary('nurse');
    expect(screen.getByText('money_nurse_earning')).toBeInTheDocument();
  });
});
