| 1 | "use client"; |
| 2 | |
| 3 | import { useUiStore } from "@/stores/ui"; |
| 4 | import { cn } from "@/lib/utils"; |
| 5 | |
| 6 | const MAP = { |
| 7 | open: { label: "Live", color: "var(--color-accent-green)", live: true }, |
| 8 | connecting: { label: "Connecting", color: "var(--color-accent-amber)", live: false }, |
| 9 | closed: { label: "Offline", color: "var(--color-accent-red)", live: false }, |
| 10 | } as const; |
| 11 | |
| 12 | export function ConnectionStatus({ compact = false }: { compact?: boolean }) { |
| 13 | const status = useUiStore((s) => s.streamStatus); |
| 14 | const m = MAP[status]; |
| 15 | return ( |
| 16 | <span |
| 17 | className={cn( |
| 18 | "inline-flex items-center gap-2 rounded-full border px-2.5 py-1 text-xs font-medium tabular", |
| 19 | compact && "px-2 py-0.5", |
| 20 | )} |
| 21 | style={{ |
| 22 | color: m.color, |
| 23 | borderColor: `color-mix(in oklch, ${m.color} 30%, transparent)`, |
| 24 | backgroundColor: `color-mix(in oklch, ${m.color} 10%, transparent)`, |
| 25 | }} |
| 26 | role="status" |
| 27 | aria-live="polite" |
| 28 | > |
| 29 | <span |
| 30 | className={cn("h-1.5 w-1.5 rounded-full", m.live && "pulse-ring")} |
| 31 | style={{ backgroundColor: m.color }} |
| 32 | aria-hidden |
| 33 | /> |
| 34 | {m.label} |
| 35 | </span> |
| 36 | ); |
| 37 | } |