import React from 'react';
import {render, screen} from '@testing-library/react';

jest.mock('next-intl', () => ({useTranslations: () => (key: string) => key}));
jest.mock('@/components/global/CarteLeafLetMultiMarker', () => ({
  __esModule: true,
  default: ({lieux}: {lieux: {title: string; position: number[]; ville: string}[]}) => (
    <div data-testid="carte" data-count={lieux.length} data-titles={lieux.map(l => l.title).join('|')} data-villes={lieux.map(l => l.ville).join('|')} data-positions={lieux.map(l => l.position.join(',')).join('|')} />
  ),
}));

import EnsembleEvenementCarte from '../EnsembleEvenementCarte';

describe('EnsembleEvenementCarte', () => {
  it('shouldPlaceEachGeolocatedEventPreferringThePlaceOverTheCity', () => {
    render(
      <EnsembleEvenementCarte
        locale="fr"
        evenements={[
          {eveId: 1, eveDate: '2026-08-08', eveLibelle: 'Grande parade', eveType: {tevLibelle: 'Défilé'}, eveVil: {vilNom: 'Lorient', vilGeoX: 47.75, vilGeoY: -3.37}, evePla: {plaLibelle: 'Espace Marine', plaGeoX: 47.74, plaGeoY: -3.36}},
          {eveId: 2, eveDate: '2026-08-10', eveLibelle: '', eveType: {tevLibelle: 'Fest-noz'}, eveVil: {vilNom: 'Lorient', vilGeoX: 47.75, vilGeoY: -3.37}, evePla: null},
          {eveId: 3, eveDate: '2026-08-11', eveLibelle: 'Sans coordonnées', eveVil: {vilNom: 'Nulle part'}, evePla: null},
        ]}
      />
    );

    const carte = screen.getByTestId('carte');
    expect(carte).toHaveAttribute('data-count', '2');
    expect(carte).toHaveAttribute('data-titles', 'Grande parade|Fest-noz Lorient');
    expect(carte).toHaveAttribute('data-villes', 'Espace Marine, Lorient|Lorient');
    expect(carte).toHaveAttribute('data-positions', '47.74,-3.36|47.75,-3.37');
    expect(screen.getByRole('heading', {level: 2})).toHaveTextContent('map_title');
  });

  it('shouldRenderNothingWithoutGeolocatedEvent', () => {
    const {container} = render(<EnsembleEvenementCarte locale="fr" evenements={[{eveId: 3, eveDate: '2026-08-11', eveVil: {vilNom: 'Nulle part'}}]} />);

    expect(container).toBeEmptyDOMElement();
  });
});
