import * as React from 'react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen } from '@testing-library/react';
import { LanguageSwitcher } from './LanguageSwitcher';
import { usePathname } from 'next/navigation';

// Mock next/navigation
vi.mock('next/navigation', () => ({
  usePathname: vi.fn(),
}));

// Mock TransitionLink to render standard anchor tag and forward all props
vi.mock('@/components/ui/TransitionLink', () => ({
  TransitionLink: ({ children, href, onClick, ...props }: any) => (
    <a href={href} onClick={onClick} {...props}>
      {children}
    </a>
  ),
}));

// Mock HoverShineOverlay
vi.mock('@/components/ui/HoverShineOverlay', () => ({
  HoverShineOverlay: () => <div data-testid="hover-shine" />,
}));

describe('LanguageSwitcher TDD', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  it('translates /en/events to /de/messen when switching to German', () => {
    vi.mocked(usePathname).mockReturnValue('/en/events');
    render(<LanguageSwitcher />);

    const deLink = screen.getByLabelText('Switch to Deutsch');
    expect(deLink.getAttribute('href')).toBe('/de/messen');
  });

  it('translates /de/messen to /en/events when switching to English', () => {
    vi.mocked(usePathname).mockReturnValue('/de/messen');
    render(<LanguageSwitcher />);

    const enLink = screen.getByLabelText('Switch to English');
    expect(enLink.getAttribute('href')).toBe('/en/events');
  });

  it('translates /en/about-us to /de/ueber-uns when switching to German', () => {
    vi.mocked(usePathname).mockReturnValue('/en/about-us');
    render(<LanguageSwitcher />);

    const deLink = screen.getByLabelText('Switch to Deutsch');
    expect(deLink.getAttribute('href')).toBe('/de/ueber-uns');
  });

  it('translates /de/ueber-uns to /en/about-us when switching to English', () => {
    vi.mocked(usePathname).mockReturnValue('/de/ueber-uns');
    render(<LanguageSwitcher />);

    const enLink = screen.getByLabelText('Switch to English');
    expect(enLink.getAttribute('href')).toBe('/en/about-us');
  });

  it('preserves nested paths like blog posts', () => {
    vi.mocked(usePathname).mockReturnValue('/de/blog/some-post');
    render(<LanguageSwitcher />);

    const enLink = screen.getByLabelText('Switch to English');
    expect(enLink.getAttribute('href')).toBe('/en/blog/some-post');
  });
});
