import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import PricingPage from '../PricingPage';

// Mock react-i18next
vi.mock('react-i18next', () => ({
  useTranslation: () => ({
    t: (key: string) => key,
  }),
}));

// Mock components
vi.mock('../../../components/marketing/PricingTable', () => ({
  default: () => <div data-testid="pricing-table">Pricing Table</div>,
}));

vi.mock('../../../components/marketing/FAQAccordion', () => ({
  default: ({ items }: { items: Array<{ question: string; answer: string }> }) => (
    <div data-testid="faq-accordion">
      {items.map((item, index) => (
        <div key={index} data-testid={`faq-item-${index}`}>
          <span>{item.question}</span>
        </div>
      ))}
    </div>
  ),
}));

vi.mock('../../../components/marketing/CTASection', () => ({
  default: () => <div data-testid="cta-section">CTA Section</div>,
}));

const renderPricingPage = () => {
  return render(
    <BrowserRouter>
      <PricingPage />
    </BrowserRouter>
  );
};

describe('PricingPage', () => {
  it('renders the page title', () => {
    renderPricingPage();
    expect(screen.getByText('marketing.pricing.title')).toBeInTheDocument();
  });

  it('renders the page subtitle', () => {
    renderPricingPage();
    expect(screen.getByText('marketing.pricing.subtitle')).toBeInTheDocument();
  });

  it('renders the PricingTable component', () => {
    renderPricingPage();
    expect(screen.getByTestId('pricing-table')).toBeInTheDocument();
  });

  it('renders the FAQ section title', () => {
    renderPricingPage();
    expect(screen.getByText('marketing.pricing.faq.title')).toBeInTheDocument();
  });

  it('renders the FAQAccordion component', () => {
    renderPricingPage();
    expect(screen.getByTestId('faq-accordion')).toBeInTheDocument();
  });

  it('renders all FAQ items', () => {
    renderPricingPage();
    expect(screen.getByTestId('faq-item-0')).toBeInTheDocument();
    expect(screen.getByTestId('faq-item-1')).toBeInTheDocument();
    expect(screen.getByTestId('faq-item-2')).toBeInTheDocument();
    expect(screen.getByTestId('faq-item-3')).toBeInTheDocument();
  });

  it('renders FAQ questions', () => {
    renderPricingPage();
    expect(screen.getByText('marketing.pricing.faq.needPython.question')).toBeInTheDocument();
    expect(screen.getByText('marketing.pricing.faq.exceedLimits.question')).toBeInTheDocument();
    expect(screen.getByText('marketing.pricing.faq.customDomain.question')).toBeInTheDocument();
    expect(screen.getByText('marketing.pricing.faq.dataSafety.question')).toBeInTheDocument();
  });

  it('renders the CTASection component', () => {
    renderPricingPage();
    expect(screen.getByTestId('cta-section')).toBeInTheDocument();
  });
});
