import { TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { Footer } from './footer';

describe('Footer', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [Footer],
      providers: [provideRouter([])],
    }).compileComponents();
  });

  it('exposes a footer landmark', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    const root = fixture.nativeElement as HTMLElement;
    expect(root.querySelector('footer[aria-label="Page footer"]')).not.toBeNull();
  });

  it('shows the APF copyright with the current year', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    const text = (fixture.nativeElement as HTMLElement).textContent ?? '';
    expect(text).toContain('APF France handicap');
    expect(text).toContain(String(new Date().getFullYear()));
  });

  it('renders the accessibility statement link (single, locale-aware via i18n)', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    const root = fixture.nativeElement as HTMLElement;
    const link = root.querySelector('a[href="/accessibility"]') as HTMLAnchorElement | null;
    expect(link).not.toBeNull();
    expect(link?.textContent?.trim()).toBe('Accessibility statement');
    // The historical `/accessibilite` link is gone — that path now
    // redirects at the route level rather than being a separate link.
    expect(root.querySelector('a[href="/accessibilite"]')).toBeNull();
  });

  it('embeds the locale switcher', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    expect(fixture.nativeElement.querySelector('app-locale-switcher')).not.toBeNull();
  });

  it('embeds the theme switcher (moved here from the header)', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    expect(fixture.nativeElement.querySelector('app-theme-switcher')).not.toBeNull();
  });

  it('groups copyright + accessibility on the left, switchers on the right', async () => {
    const fixture = TestBed.createComponent(Footer);
    await fixture.whenStable();
    const root = fixture.nativeElement as HTMLElement;
    const clusters = Array.from(root.querySelectorAll('footer > div'));
    expect(clusters).toHaveLength(2);
    // Left cluster — info / legal.
    expect(clusters[0]?.querySelector('p')?.textContent).toContain('APF France handicap');
    expect(clusters[0]?.querySelector('a[href="/accessibility"]')).not.toBeNull();
    // Right cluster — device preferences.
    expect(clusters[1]?.querySelector('app-locale-switcher')).not.toBeNull();
    expect(clusters[1]?.querySelector('app-theme-switcher')).not.toBeNull();
  });
});
