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

// next-intl is mocked to echo keys; 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 ServicePriceRow from './ServicePriceRow';

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

describe('<ServicePriceRow/> component', () => {
  it('renders the service name', () => {
    renderRow({ displayName: 'Daytime elderly care', priceIrr: '2800000', priceUnit: 'per_hour' });
    expect(screen.getByText('Daytime elderly care')).toBeInTheDocument();
  });

  it('renders the price as grouped Toman via the shared money display', () => {
    // 2,800,000 IRR = 280,000 Toman.
    renderRow({ displayName: 'Daytime elderly care', priceIrr: '2800000', priceUnit: 'per_hour' });
    expect(screen.getByText(/280,000/)).toBeInTheDocument();
  });

  it('renders the unit label off the price_unit code (never hardcoded)', () => {
    renderRow({ displayName: 'Live-in care', priceIrr: '85000000', priceUnit: 'per_24h' });
    expect(screen.getByText('unit_per_24h')).toBeInTheDocument();
  });
});
