/**
 * Tests for StepIndicator component
 */

import { render, screen } from '@testing-library/react';
import { StepIndicator } from '@/components/projects/wizard/StepIndicator';

describe('StepIndicator', () => {
  describe('non-script mode (6 steps)', () => {
    it('renders correct step count', () => {
      render(<StepIndicator currentStep={1} isScriptMode={false} />);
      expect(screen.getByText('Step 1 of 6')).toBeInTheDocument();
    });

    it('shows correct step label for each step', () => {
      const { rerender } = render(<StepIndicator currentStep={1} isScriptMode={false} />);
      expect(screen.getByText('Basic Info')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={2} isScriptMode={false} />);
      expect(screen.getByText('Complexity')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={3} isScriptMode={false} />);
      expect(screen.getByText('Client Mode')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={4} isScriptMode={false} />);
      expect(screen.getByText('Autonomy')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={5} isScriptMode={false} />);
      expect(screen.getByText('Agent Chat')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={6} isScriptMode={false} />);
      expect(screen.getByText('Review')).toBeInTheDocument();
    });

    it('renders 6 progress segments', () => {
      render(<StepIndicator currentStep={3} isScriptMode={false} />);
      const progressbar = screen.getByRole('progressbar');
      expect(progressbar).toBeInTheDocument();
      expect(progressbar).toHaveAttribute('aria-valuenow', '3');
      expect(progressbar).toHaveAttribute('aria-valuemax', '6');
    });
  });

  describe('script mode (4 steps)', () => {
    it('renders correct step count', () => {
      render(<StepIndicator currentStep={1} isScriptMode={true} />);
      expect(screen.getByText('Step 1 of 4')).toBeInTheDocument();
    });

    it('shows correct step labels (no Client Mode or Autonomy)', () => {
      const { rerender } = render(<StepIndicator currentStep={1} isScriptMode={true} />);
      expect(screen.getByText('Basic Info')).toBeInTheDocument();

      rerender(<StepIndicator currentStep={2} isScriptMode={true} />);
      expect(screen.getByText('Complexity')).toBeInTheDocument();

      // Step 5 (Agent Chat) maps to display step 3
      rerender(<StepIndicator currentStep={5} isScriptMode={true} />);
      expect(screen.getByText('Step 3 of 4')).toBeInTheDocument();
      expect(screen.getByText('Agent Chat')).toBeInTheDocument();

      // Step 6 (Review) maps to display step 4
      rerender(<StepIndicator currentStep={6} isScriptMode={true} />);
      expect(screen.getByText('Step 4 of 4')).toBeInTheDocument();
      expect(screen.getByText('Review')).toBeInTheDocument();
    });

    it('renders 4 progress segments', () => {
      render(<StepIndicator currentStep={5} isScriptMode={true} />);
      const progressbar = screen.getByRole('progressbar');
      expect(progressbar).toHaveAttribute('aria-valuemax', '4');
    });
  });

  it('applies custom className', () => {
    const { container } = render(
      <StepIndicator currentStep={1} isScriptMode={false} className="my-custom-class" />
    );
    expect(container.firstChild).toHaveClass('my-custom-class');
  });
});
