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

jest.mock('next-intl', () => ({
  useTranslations: () => (key: string) => key,
  useLocale: () => 'en',
}));

import SessionList from './SessionList';
import type { BookingSessionDto } from '@/services/bookings/types';

function makeSession(id: number, sessionIndex: number): BookingSessionDto {
  return {
    id,
    sessionIndex,
    scheduledDate: '2026-08-01',
    scheduledTimeStart: '09:00:00',
    scheduledTimeEnd: '13:00:00',
    status: 'scheduled',
    visitPayoutAmount: '13200000',
    payoutEligibleAt: null,
    evvStatus: 'pending',
    checkInAt: null,
    checkOutAt: null,
    checkInAddressMatch: null,
  };
}

function renderList(sessions: BookingSessionDto[]) {
  return render(
    <ThemeProvider>
      <SessionList sessions={sessions} />
    </ThemeProvider>,
  );
}

describe('<SessionList/> component', () => {
  it('renders one card per session', () => {
    renderList([makeSession(1, 1), makeSession(2, 2), makeSession(3, 3)]);
    expect(screen.getAllByText('session_index')).toHaveLength(3);
  });

  it('renders exactly one card for a single-visit booking (no special case)', () => {
    renderList([makeSession(1, 1)]);
    expect(screen.getAllByText('session_index')).toHaveLength(1);
  });
});
