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

// next-intl is mocked to echo keys (and honour {count} in estimate_for), locale = en so the money
// util groups with ASCII digits we can assert on.
jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
  useLocale: () => 'en',
}));

import PriceDisplay from './PriceDisplay';

function renderPrice(props: React.ComponentProps<typeof PriceDisplay>) {
  return render(
    <ThemeProvider>
      <PriceDisplay {...props} />
    </ThemeProvider>,
  );
}

describe('<PriceDisplay/> component', () => {
  it('renders the price as grouped Toman with the unit label off the price_unit code', () => {
    // 2,800,000 IRR = 280,000 Toman, per hour.
    renderPrice({ price: '2800000', priceUnit: 'per_hour' });
    expect(screen.getByText(/280,000/)).toBeInTheDocument();
    expect(screen.getByText('unit_per_hour')).toBeInTheDocument();
  });

  it('does not render an estimated total from price alone (no sessionCount)', () => {
    renderPrice({ price: '2800000', priceUnit: 'per_hour', showEstimate: true });
    expect(screen.queryByText('estimate_label', { exact: false })).not.toBeInTheDocument();
  });

  it('renders the unit-aware estimated total = price × sessionCount when asked', () => {
    // 2,800,000 IRR/hr × 6 = 16,800,000 IRR = 1,680,000 Toman.
    renderPrice({ price: '2800000', priceUnit: 'per_hour', sessionCount: 6, showEstimate: true });
    expect(screen.getByText(/estimate_label/)).toBeInTheDocument();
    expect(screen.getByText(/1,680,000/)).toBeInTheDocument();
  });
});
