import { render, screen } from '@testing-library/react';
import TermsText from '@/app/components/TermsText';

/**
 * TermsText Component Tests
 *
 * Tests the shared terms content component used by both:
 * - /terms/ (public read-only page)
 * - /registration/terms (registration flow with checkbox)
 *
 * Note: The /terms/page.tsx is a simple server component that renders
 * TermsText with styling. Testing TermsText ensures content correctness.
 */
describe('TermsText', () => {
  describe('Content', () => {
    test('renders main title', () => {
      render(<TermsText />);
      expect(screen.getByText('TERMS OF SERVICE:')).toBeInTheDocument();
    });

    test('renders agreement subtitle', () => {
      render(<TermsText />);
      expect(
        screen.getByText('Dealer Subscription Agreement for the AMSOIL Dealer Lead Page Program')
      ).toBeInTheDocument();
    });

    test('renders key legal sections', () => {
      render(<TermsText />);

      // Check major section headings are present
      expect(screen.getByText('DEFINITIONS')).toBeInTheDocument();
      expect(screen.getByText('2. ORDERING AND SERVICES')).toBeInTheDocument();
      expect(
        screen.getByText(
          '3. USE OF THE SERVICE PROVIDER SUBSCRIPTION SERVICES AND PROPRIETARY RIGHTS'
        )
      ).toBeInTheDocument();
      expect(screen.getByText('4. TITLE')).toBeInTheDocument();
      expect(screen.getByText('5. PAYMENT')).toBeInTheDocument();
      expect(screen.getByText('6. DISCLAIMER')).toBeInTheDocument();
      expect(screen.getByText('7. SECURITY AND CONFIDENTIAL INFORMATION')).toBeInTheDocument();
      expect(screen.getByText('8. TERM AND TERMINATION')).toBeInTheDocument();
      expect(screen.getByText('9. INDEMNITY')).toBeInTheDocument();
      expect(screen.getByText('10. LIMITATION OF LIABILITY')).toBeInTheDocument();
      expect(screen.getByText('11. GENERAL')).toBeInTheDocument();
    });

    test('renders exhibits', () => {
      render(<TermsText />);

      expect(screen.getByText('EXHIBIT A – SECURITY ADDENDUM')).toBeInTheDocument();
      expect(screen.getByText('EXHIBIT B – SLA')).toBeInTheDocument();
    });

    test('renders AIMCLEAR contact information', () => {
      render(<TermsText />);

      // Check that AIMCLEAR contact info is present (for DMCA notices)
      expect(screen.getByText(/team-amsoil-dlp@aimclear.com/)).toBeInTheDocument();
      expect(screen.getByText(/9 W Superior Street #200, Duluth, MN 55802/)).toBeInTheDocument();
    });

    test('renders SLA uptime guarantee', () => {
      render(<TermsText />);

      // Check the 99.9% uptime guarantee is mentioned
      expect(screen.getByText(/99\.9% of the time/)).toBeInTheDocument();
    });
  });
});
