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

jest.mock('next/link', () => {
  return ({children, href, ...props}: {children: React.ReactNode; href: string; [key: string]: unknown}) => (
    <a href={href} {...props}>{children}</a>
  );
});

jest.mock('../SoutiensLogos', () => ({__esModule: true, default: ({locale}: {locale: string}) => <div data-testid="soutiens-logos" data-locale={locale} />}));
jest.mock('../AffichesAdherents', () => ({__esModule: true, default: ({locale}: {locale: string}) => <div data-testid="affiches-adherents" data-locale={locale} />}));

describe('FooterV2', () => {
  it('shouldMountTheSupportersLogosAndTheMemberPostersBlocks', () => {
    render(<FooterV2 locale="bzh" />);
    expect(screen.getByTestId('soutiens-logos')).toHaveAttribute('data-locale', 'bzh');
    expect(screen.getByTestId('affiches-adherents')).toHaveAttribute('data-locale', 'bzh');
  });

  it('renders a link to the supporters page', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_discover_soutiens').closest('a')).toHaveAttribute('href', '/fr/soutiens');
  });

  it('shouldLinkToTheProAreaInANewTab', () => {
    render(<FooterV2 locale="fr" />);
    const lien = screen.getByText('footer_community_pro').closest('a');
    expect(lien).toHaveAttribute('href', 'https://pro.tamm-kreiz.bzh');
    expect(lien).toHaveAttribute('target', '_blank');
  });

  it('renders the logo with Tamm and Kreiz spans', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('Tamm')).toBeInTheDocument();
    expect(screen.getByText('Kreiz')).toBeInTheDocument();
  });

  it('renders the 3 column headings', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_discover')).toBeInTheDocument();
    expect(screen.getByText('footer_community')).toBeInTheDocument();
    expect(screen.getByText('footer_newsletter_title')).toBeInTheDocument();
  });

  it('renders 3 social icons (no YouTube)', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByLabelText('Facebook')).toBeInTheDocument();
    expect(screen.getByLabelText('Twitter')).toBeInTheDocument();
    expect(screen.getByLabelText('Instagram')).toBeInTheDocument();
    expect(screen.queryByLabelText('YouTube')).not.toBeInTheDocument();
  });

  it('renders copyright', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_copyright')).toBeInTheDocument();
  });

  it('renders tagline', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_tagline')).toBeInTheDocument();
  });

  it('renders "Code with" text', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_code_with')).toBeInTheDocument();
  });

  it('renders 5 discover links', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_discover_agenda')).toBeInTheDocument();
    expect(screen.getByText('footer_discover_annuaire')).toBeInTheDocument();
    expect(screen.getByText('footer_discover_mag')).toBeInTheDocument();
    expect(screen.getByText('footer_discover_carte')).toBeInTheDocument();
    expect(screen.getByText('footer_discover_top')).toBeInTheDocument();
  });

  it('renders a link to the EPCI list', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_discover_epci').closest('a')).toHaveAttribute(
      'href',
      '/fr/localisation/epci'
    );
  });

  it('renders 5 community links', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_community_login')).toBeInTheDocument();
    expect(screen.getByText('footer_community_propose')).toBeInTheDocument();
    expect(screen.getByText('footer_community_forum')).toBeInTheDocument();
    expect(screen.getByText('footer_community_benevole')).toBeInTheDocument();
    expect(screen.getByText('footer_community_don')).toBeInTheDocument();
  });

  it('renders a link to the carpooling page', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_community_covoiturage').closest('a')).toHaveAttribute('href', '/fr/covoiturage');
  });

  it('renders newsletter subtitle', () => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText('footer_newsletter_subtitle')).toBeInTheDocument();
  });

  it.each([
    ['footer_legal_about', '/fr/association'],
    ['footer_legal_mentions', '/fr/mentions-legales'],
    ['footer_legal_terms', '/fr/conditions-utilisation'],
    ['footer_legal_privacy', '/fr/confidentialite'],
    ['footer_legal_contact', '/fr/contact'],
  ])('renders the legal link %s to %s', (label, href) => {
    render(<FooterV2 locale="fr" />);
    expect(screen.getByText(label).closest('a')).toHaveAttribute('href', href);
  });
});
