import { Loader2 } from "lucide-react";
import { Badge, type BadgeProps } from "@/components/ui/badge";

// Keyed by the Prisma EpisodeStatus enum values (kept as strings to avoid
// importing the Prisma client into client bundles).
const MAP: Record<string, { label: string; variant: BadgeProps["variant"]; spin?: boolean }> = {
  DRAFT: { label: "Draft", variant: "secondary" },
  QUEUED: { label: "Queued", variant: "secondary", spin: true },
  SCRIPTING: { label: "Writing script", variant: "warning", spin: true },
  SYNTHESIZING: { label: "Recording audio", variant: "warning", spin: true },
  STITCHING: { label: "Mixing audio", variant: "warning", spin: true },
  ART: { label: "Designing art", variant: "warning", spin: true },
  SAVING: { label: "Finalizing", variant: "warning", spin: true },
  READY: { label: "Ready", variant: "success" },
  FAILED: { label: "Failed", variant: "destructive" },
};

export function EpisodeStatusBadge({ status }: { status: string }) {
  const config = MAP[status] ?? { label: status, variant: "secondary" as const };
  return (
    <Badge variant={config.variant} className="gap-1.5 whitespace-nowrap">
      {config.spin && <Loader2 className="h-3 w-3 animate-spin" />}
      {config.label}
    </Badge>
  );
}
