import { cn } from "@/lib/utils";

export type StatusPillTone = "success" | "danger" | "muted" | "warning" | "indigo";

const toneStyles: Record<StatusPillTone, string> = {
  success: "bg-green-100 text-green-800",
  danger: "bg-red-100 text-red-800",
  muted: "bg-slate-200 text-slate-700",
  warning: "bg-amber-100 text-amber-900",
  indigo: "bg-indigo-100 text-indigo-800",
};

type StatusPillProps = {
  label: string;
  tone: StatusPillTone;
  rounded?: "default" | "full";
  className?: string;
  uppercase?: boolean;
};

export function StatusPill({
  label,
  tone,
  rounded = "default",
  className,
  uppercase = true,
}: StatusPillProps) {
  return (
    <span
      className={cn(
        "inline-flex px-2 py-0.5 font-medium text-[11px] tracking-wide",
        uppercase ? "uppercase" : "capitalize",
        rounded === "full" ? "rounded-full" : "rounded",
        toneStyles[tone],
        className,
      )}
    >
      {label}
    </span>
  );
}

export function ActiveInactiveBadge({
  status,
  label,
}: {
  status: "active" | "inactive";
  label: string;
}) {
  return <StatusPill label={label} tone={status === "active" ? "success" : "danger"} />;
}

export function EnabledDisabledBadge({
  status,
  label,
}: {
  status: "enabled" | "disabled";
  label: string;
}) {
  return <StatusPill label={label} tone={status === "enabled" ? "success" : "danger"} />;
}

export function ActiveReviewBadge({
  status,
  label,
}: {
  status: "A" | "I" | "R";
  label: string;
}) {
  const tone: StatusPillTone =
    status === "A" ? "success" : status === "I" ? "danger" : "warning";

  return <StatusPill label={label} tone={tone} />;
}

export function StatusBadgeFromTone({
  label,
  tone,
}: {
  label: string;
  tone: StatusPillTone;
}) {
  return <StatusPill label={label} tone={tone} />;
}
