import type { RequisitionStatus, RequisitionReason } from "@prisma/client";
import type { BadgeProps } from "@/components/ui/badge";

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

// Status → badge variant (Crewing-Implementation-Spec §8.2).
export const STATUS_VARIANT: Record<RequisitionStatus, Variant> = {
  OPEN: "outline",
  SHORTLISTING: "default",
  PROPOSING: "default",
  INTERVIEWING: "warning",
  SELECTED: "default",
  FILLED: "success",
  CANCELLED: "danger",
};

export const STATUS_LABEL: Record<RequisitionStatus, string> = {
  OPEN: "Open",
  SHORTLISTING: "Shortlisting",
  PROPOSING: "Proposing",
  INTERVIEWING: "Interviewing",
  SELECTED: "Selected",
  FILLED: "Filled",
  CANCELLED: "Cancelled",
};

export const REASON_LABEL: Record<RequisitionReason, string> = {
  NEW_VACANCY: "New vacancy",
  REPLACEMENT: "Replacement",
  LEAVE: "Leave cover",
  SIGN_OFF: "Sign-off",
  END_OF_CONTRACT: "End of contract",
  OTHER: "Other",
};

export const REASON_OPTIONS: RequisitionReason[] = [
  "NEW_VACANCY",
  "REPLACEMENT",
  "LEAVE",
  "SIGN_OFF",
  "END_OF_CONTRACT",
  "OTHER",
];

// Compact "age" label (e.g. "3d", "5h", "12m") relative to now.
export function ageLabel(iso: string): string {
  const mins = Math.floor((Date.now() - new Date(iso).getTime()) / 60_000);
  if (mins < 60) return `${Math.max(mins, 0)}m`;
  const hrs = Math.floor(mins / 60);
  if (hrs < 24) return `${hrs}h`;
  return `${Math.floor(hrs / 24)}d`;
}
