import type { CRMStage } from "@/types";

const LABELS: Record<CRMStage, string> = {
  LEAD: "Lead",
  CONTACTED: "Contacted",
  WARM: "Warm",
  HOT: "Hot",
  ACTIVE_PARTNER: "Active",
  PREMIUM_PARTNER: "Premium",
  INACTIVE: "Inactive",
  LOST: "Lost",
};

const STYLES: Record<CRMStage, string> = {
  LEAD: "bg-gray-100 text-gray-700",
  CONTACTED: "bg-sky-100 text-sky-700",
  WARM: "bg-amber-100 text-amber-700",
  HOT: "bg-orange-100 text-orange-700",
  ACTIVE_PARTNER: "bg-emerald-100 text-emerald-700",
  PREMIUM_PARTNER: "bg-purple-100 text-purple-700",
  INACTIVE: "bg-slate-200 text-slate-700",
  LOST: "bg-red-100 text-red-700",
};

function isStage(value?: string | null): value is CRMStage {
  return !!value && value in LABELS;
}

export function CrmStageBadge({ stage }: { stage?: CRMStage | string | null }) {
  if (!isStage(stage)) {
    return <span className="inline-flex rounded-full bg-gray-100 px-2.5 py-1 text-xs font-semibold text-gray-600">Unstaged</span>;
  }

  return (
    <span className={`inline-flex rounded-full px-2.5 py-1 text-xs font-semibold ${STYLES[stage]}`}>
      {LABELS[stage]}
    </span>
  );
}
