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

// next-intl mocked to read the REAL fa message file, so the test pins the product-mandated escrow copy
// as it actually ships — a rewording in fa.json (or a broken key) fails here as a conscious change.
jest.mock('next-intl', () => ({
  useTranslations: (namespace: string) => (key: string) => {
    const messages = jest.requireActual('../../../messages/fa.json') as Record<string, Record<string, string>>;
    return messages[namespace][key];
  },
}));

import EscrowNotice from './EscrowNotice';

function renderNotice() {
  return render(
    <ThemeProvider>
      <EscrowNotice />
    </ThemeProvider>,
  );
}

describe('<EscrowNotice/> component', () => {
  it('renders the mandated escrow copy verbatim from fa.json', () => {
    renderNotice();
    expect(
      screen.getByText('مبلغ به‌صورت امانی نزد بالین‌یار می‌ماند و پس از پایان ویزیت آزاد می‌شود'),
    ).toBeInTheDocument();
    expect(screen.getByText(faMessages.payment.escrow_notice)).toBeInTheDocument();
  });

  it('renders as an info (trust) surface, never an error tone', () => {
    renderNotice();
    const alert = screen.getByTestId('escrow-notice');
    expect(alert.className).toContain('MuiAlert-colorInfo');
    expect(alert.className).not.toContain('MuiAlert-colorError');
  });
});
