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

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string, values?: Record<string, unknown>) =>
    values ? `${key}:${JSON.stringify(values)}` : key,
  useLocale: () => 'en',
}));

import Pager from './Pager';

describe('<Pager/>', () => {
  const wrap = (ui: React.ReactNode) => render(<ThemeProvider>{ui}</ThemeProvider>);

  it('renders nothing for a single page', () => {
    const { container } = wrap(<Pager page={1} pageCount={1} onPrev={jest.fn()} onNext={jest.fn()} />);
    expect(container).toBeEmptyDOMElement();
  });

  it('disables prev on the first page and next on the last', () => {
    wrap(<Pager page={1} pageCount={3} onPrev={jest.fn()} onNext={jest.fn()} />);
    expect(screen.getByText('page_prev')).toBeDisabled();
    expect(screen.getByText('page_next')).not.toBeDisabled();
  });

  it('fires onPrev/onNext', () => {
    const onPrev = jest.fn();
    const onNext = jest.fn();
    wrap(<Pager page={2} pageCount={3} onPrev={onPrev} onNext={onNext} />);
    fireEvent.click(screen.getByText('page_prev'));
    fireEvent.click(screen.getByText('page_next'));
    expect(onPrev).toHaveBeenCalledTimes(1);
    expect(onNext).toHaveBeenCalledTimes(1);
  });
});
