import { CheckCircleIcon } from "@heroicons/react/24/outline";

interface Step {
  number: number;
  title: string;
  completed: boolean;
}

interface ProgressStepsProps {
  steps: Step[];
  currentStep?: number; // Optional for step-based navigation
  className?: string;
}

function getStepCircleStyles(step: Step, currentStep: number | undefined): string {
  if (step.completed) {
    return "bg-success border-success text-success-foreground";
  }
  if (currentStep === step.number) {
    return "border-primary text-primary bg-accent";
  }
  return "border-border text-muted-foreground bg-card";
}

function getStepTextStyles(step: Step, currentStep: number | undefined): string {
  if (step.completed) {
    return "text-success";
  }
  if (currentStep === step.number) {
    return "text-primary";
  }
  return "text-muted-foreground";
}

export function ProgressSteps({ steps, currentStep, className = "" }: ProgressStepsProps) {
  return (
    <div className={`mb-8 ${className}`}>
      <div className="bg-card text-card-foreground p-6 rounded-xl shadow-[var(--cp-shadow-1)] border border-border">
        <div className="overflow-x-auto">
          <div className="flex items-center justify-center space-x-3 md:space-x-4 min-w-max px-2">
            {steps.map((step, index) => (
              <div key={step.number} className="flex items-center flex-shrink-0">
                <div className="flex flex-col items-center gap-2">
                  <div
                    className={`relative flex items-center justify-center w-10 h-10 md:w-12 md:h-12 rounded-full border-2 transition-all duration-200 ease-out ${getStepCircleStyles(step, currentStep)}`}
                  >
                    {step.completed ? (
                      <CheckCircleIcon className="w-6 h-6 md:w-7 md:h-7 transition-all duration-150" />
                    ) : (
                      <span className="font-bold text-sm md:text-base transition-all duration-150">
                        {step.number}
                      </span>
                    )}
                  </div>
                  <span
                    className={`text-xs md:text-sm font-medium text-center transition-all duration-150 max-w-[80px] md:max-w-none ${getStepTextStyles(step, currentStep)}`}
                  >
                    {step.title}
                  </span>
                </div>
                {index < steps.length - 1 && (
                  <div className="relative w-10 md:w-16 h-[2px] mx-2 md:mx-4 flex-shrink-0">
                    <div className="absolute inset-0 bg-border rounded-full" />
                    <div
                      className={`absolute inset-0 rounded-full transition-all duration-300 ease-out ${
                        step.completed ? "bg-success" : "bg-border"
                      }`}
                      style={{
                        transform: step.completed ? "scaleX(1)" : "scaleX(0)",
                        transformOrigin: "left",
                      }}
                    />
                  </div>
                )}
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}

export type { ProgressStepsProps, Step };
