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

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

// Mock components
vi.mock('../../../components/marketing/CodeBlock', () => ({
  default: ({ code, filename }: { code: string; filename: string }) => (
    <div data-testid="code-block">
      <div data-testid="code-filename">{filename}</div>
      <pre>{code}</pre>
    </div>
  ),
}));

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

const renderFeaturesPage = () => {
  return render(
    <BrowserRouter>
      <FeaturesPage />
    </BrowserRouter>
  );
};

describe('FeaturesPage', () => {
  it('renders the page title', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.pageTitle')).toBeInTheDocument();
  });

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

  it('renders the automation engine section', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.automationEngine.title')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.automationEngine.badge')).toBeInTheDocument();
  });

  it('renders automation engine features list', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.automationEngine.features.recurringJobs')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.automationEngine.features.customLogic')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.automationEngine.features.fullContext')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.automationEngine.features.zeroInfrastructure')).toBeInTheDocument();
  });

  it('renders the code block example', () => {
    renderFeaturesPage();
    expect(screen.getByTestId('code-block')).toBeInTheDocument();
    expect(screen.getByTestId('code-filename')).toHaveTextContent('webhook_plugin.py');
  });

  it('renders the multi-tenancy section', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.multiTenancy.title')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.multiTenancy.badge')).toBeInTheDocument();
  });

  it('renders multi-tenancy features', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.multiTenancy.customDomains.title')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.multiTenancy.whiteLabeling.title')).toBeInTheDocument();
  });

  it('renders the contracts section', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.contracts.title')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.contracts.badge')).toBeInTheDocument();
  });

  it('renders contracts features list', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.contracts.features.templates')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.contracts.features.eSignature')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.contracts.features.auditTrail')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.contracts.features.pdfGeneration')).toBeInTheDocument();
  });

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

  it('renders compliance and automation sections', () => {
    renderFeaturesPage();
    expect(screen.getByText('marketing.features.contracts.compliance.title')).toBeInTheDocument();
    expect(screen.getByText('marketing.features.contracts.automation.title')).toBeInTheDocument();
  });
});
