import type { ApplicationStage } from "@prisma/client";
import type { BadgeProps } from "@/components/ui/badge";

type Variant = NonNullable<BadgeProps["variant"]>;

// The 7 board columns in order (mirrors lib/application-pipeline BOARD_STAGES;
// kept here as a client-safe constant for the stepper/board UI).
export const STAGE_ORDER: ApplicationStage[] = [
  "SHORTLISTED",
  "COMPETENCY_AND_REFERENCES",
  "DOC_VERIFICATION",
  "SALARY_AGREEMENT",
  "PROPOSED",
  "INTERVIEW",
  "SELECTED",
];

export const STAGE_LABEL: Record<ApplicationStage, string> = {
  SHORTLISTED: "Shortlisted",
  COMPETENCY_AND_REFERENCES: "Competency & references",
  DOC_VERIFICATION: "Documents",
  SALARY_AGREEMENT: "Salary",
  PROPOSED: "Proposed",
  INTERVIEW: "Interview",
  SELECTED: "Selected",
  REJECTED: "Rejected",
  ONBOARDED: "Onboarded",
};

export const STAGE_VARIANT: Record<ApplicationStage, Variant> = {
  SHORTLISTED: "outline",
  COMPETENCY_AND_REFERENCES: "default",
  DOC_VERIFICATION: "default",
  SALARY_AGREEMENT: "warning",
  PROPOSED: "default",
  INTERVIEW: "warning",
  SELECTED: "success",
  REJECTED: "danger",
  ONBOARDED: "success",
};

// Index of a stage within the 7-step flow (−1 for REJECTED; 7 for ONBOARDED).
export function stageIndex(stage: ApplicationStage): number {
  if (stage === "REJECTED") return -1;
  if (stage === "ONBOARDED") return STAGE_ORDER.length;
  return STAGE_ORDER.indexOf(stage);
}
