import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { Footer } from '../footer';

describe('Footer', () => {
  it('should render brand name', () => {
    render(<Footer />);
    expect(screen.getByText('宇之然 AI')).toBeInTheDocument();
  });

  it('should render mission statement', () => {
    render(<Footer />);
    expect(screen.getByText('让每个人都能用好 AI')).toBeInTheDocument();
  });

  it('should render navigation links', () => {
    render(<Footer />);
    expect(screen.getByText('课程')).toBeInTheDocument();
    expect(screen.getByText('提示词库')).toBeInTheDocument();
    expect(screen.getByText('AI 工具')).toBeInTheDocument();
  });

  it('should render about links', () => {
    render(<Footer />);
    expect(screen.getByText('关于我们')).toBeInTheDocument();
    expect(screen.getByText('隐私政策')).toBeInTheDocument();
    expect(screen.getByText('服务协议')).toBeInTheDocument();
    expect(screen.getByText('AI 服务协议')).toBeInTheDocument();
  });

  it('should render contact info', () => {
    render(<Footer />);
    expect(screen.getByText(/contact@yuzhiran\.com/)).toBeInTheDocument();
    expect(screen.getByText('北京宇之然科技中心')).toBeInTheDocument();
  });

  it('should render ICP and gongan beian links', () => {
    render(<Footer />);
    const icpLink = screen.getByText('京ICP备2026007249号-1');
    expect(icpLink).toBeInTheDocument();
    expect(icpLink.closest('a')).toHaveAttribute('href', 'https://beian.miit.gov.cn/');

    const gonganLink = screen.getByText('京公网安备11011502039545号');
    expect(gonganLink).toBeInTheDocument();
    expect(gonganLink.closest('a')).toHaveAttribute('href', 'https://beian.mps.gov.cn/#/query/webSearch?code=11011502039545');
  });

  it('should render QR code section', () => {
    render(<Footer />);
    expect(screen.getByText('微信公众号')).toBeInTheDocument();
    expect(screen.getByText('微信服务号')).toBeInTheDocument();
    expect(screen.getByText('小程序')).toBeInTheDocument();
    expect(screen.getByText('微信客服')).toBeInTheDocument();
  });

  it('should render copyright with current year', () => {
    render(<Footer />);
    const year = String(new Date().getFullYear());
    expect(screen.getAllByText(new RegExp(year)).length).toBeGreaterThanOrEqual(1);
  });

  it('should have correct links for navigation items', () => {
    render(<Footer />);
    const coursesLink = screen.getByText('课程').closest('a');
    expect(coursesLink).toHaveAttribute('href', '/courses');

    const privacyLink = screen.getByText('隐私政策').closest('a');
    expect(privacyLink).toHaveAttribute('href', '/privacy');

    const termsLink = screen.getByText('服务协议').closest('a');
    expect(termsLink).toHaveAttribute('href', '/terms');

    const aiAgreementLink = screen.getByText('AI 服务协议').closest('a');
    expect(aiAgreementLink).toHaveAttribute('href', '/ai-agreement');
  });
});
