import type { ReactNode } from "react"; type StatusTone = "info" | "success" | "warning" | "danger" | "neutral"; const STATUS_PRESENTATION: Record< string, { icon: string; label: string; tone: StatusTone } > = { OPEN: { icon: "○", label: "Open", tone: "info" }, IN_PROGRESS: { icon: "◐", label: "In progress", tone: "warning" }, COMPLETED: { icon: "✓", label: "Completed", tone: "success" }, CANCELLED: { icon: "—", label: "Cancelled", tone: "neutral" }, LIVE: { icon: "●", label: "Live", tone: "success" }, CONNECTING: { icon: "↻", label: "Connecting", tone: "info" }, OFFLINE: { icon: "○", label: "Offline · reconnecting", tone: "warning" }, ERROR: { icon: "!", label: "Connection error · retrying", tone: "danger" }, }; export function humanizeStatus(status: string): string { return ( STATUS_PRESENTATION[status]?.label ?? status .toLowerCase() .split("_") .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" ") ); } export function StatusBadge({ status, label, }: { status: string; label?: string; }) { const presentation = STATUS_PRESENTATION[status] ?? { icon: "•", label: humanizeStatus(status), tone: "neutral" as const, }; return ( {label ?? presentation.label} ); } export function PageState({ kind, title, children, }: { kind: "loading" | "empty" | "error"; title: string; children?: ReactNode; }) { const icon = kind === "error" ? "!" : kind === "empty" ? "□" : "…"; return (