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

const STATUS: Record<string, { label: string; dot: string; text: string; live?: boolean }> = {
  succeeded: { label: "Succeeded", dot: "bg-success", text: "text-success" },
  ok: { label: "OK", dot: "bg-success", text: "text-success" },
  ready: { label: "Ready", dot: "bg-success", text: "text-success" },
  approved: { label: "Approved", dot: "bg-success", text: "text-success" },
  running: { label: "Running", dot: "bg-info", text: "text-info", live: true },
  processing: { label: "Processing", dot: "bg-info", text: "text-info", live: true },
  pending: { label: "Pending", dot: "bg-faint", text: "text-muted", live: true },
  untested: { label: "Untested", dot: "bg-faint", text: "text-muted" },
  waiting_approval: { label: "Awaiting approval", dot: "bg-warning", text: "text-warning", live: true },
  failed: { label: "Failed", dot: "bg-danger", text: "text-danger" },
  error: { label: "Error", dot: "bg-danger", text: "text-danger" },
  denied: { label: "Denied", dot: "bg-danger", text: "text-danger" },
  rejected: { label: "Rejected", dot: "bg-danger", text: "text-danger" },
  cancelled: { label: "Cancelled", dot: "bg-faint", text: "text-muted" },
  expired: { label: "Expired", dot: "bg-faint", text: "text-muted" },
};

export function StatusPill({ status, className }: { status: string; className?: string }) {
  const s = STATUS[status] ?? { label: status, dot: "bg-faint", text: "text-muted" };
  return (
    <span
      className={cn(
        "inline-flex items-center gap-2 rounded-full border border-line bg-surface/60 px-2.5 py-1 text-xs font-medium",
        s.text,
        className
      )}
    >
      <span className={cn("h-1.5 w-1.5 rounded-full", s.dot, s.live && "animate-pulse-soft")} />
      {s.label}
    </span>
  );
}
