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

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

import RefundEtaBanner, { RefundEtaBannerProps } from './RefundEtaBanner';

const ComponentToTest: FunctionComponent<RefundEtaBannerProps> = (props) => (
  <ThemeProvider>
    <RefundEtaBanner {...props} />
  </ThemeProvider>
);

describe('<RefundEtaBanner/> component', () => {
  it('renders the BNPL wording + the ~7–10 business-day window and the ETA', () => {
    const { container } = render(<ComponentToTest channel="bnpl_revert" eta="2026-08-24" />);
    expect(container.querySelector('[data-channel="bnpl_revert"]')).toBeInTheDocument();
    expect(screen.getByText('eta_bnpl_title')).toBeInTheDocument();
    // The honest window note only renders for the BNPL channel.
    expect(screen.getByTestId('refund-eta-window')).toBeInTheDocument();
  });

  it('renders the card wording and no BNPL window for a card refund', () => {
    render(<ComponentToTest channel="psp_card" eta={null} />);
    expect(screen.getByText('eta_card_title')).toBeInTheDocument();
    expect(screen.queryByTestId('refund-eta-window')).not.toBeInTheDocument();
  });

  it('renders the manual-transfer wording for a manual refund', () => {
    render(<ComponentToTest channel="manual" eta={null} />);
    expect(screen.getByText('eta_manual_title')).toBeInTheDocument();
    expect(screen.queryByTestId('refund-eta-window')).not.toBeInTheDocument();
  });
});
