import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { cn } from "@/lib/utils"; import { useClient } from "@/providers/ClientProvider"; import type { ConnectionStatus } from "@/lib/types"; const COPY: Record = { idle: { color: "text-muted-foreground" }, connecting: { color: "text-amber-700 dark:text-amber-300", }, open: { color: "text-emerald-700 dark:text-emerald-400", }, reconnecting: { color: "text-amber-700 dark:text-amber-300", }, closed: { color: "text-muted-foreground", }, error: { color: "text-destructive", }, }; export function ConnectionBadge() { const { t } = useTranslation(); const { client } = useClient(); const [status, setStatus] = useState(client.status); useEffect(() => client.onStatus(setStatus), [client]); const meta = COPY[status]; const pulsing = status === "connecting" || status === "reconnecting" || status === "error"; return ( {pulsing && ( )} {t(`connection.${status}`)} ); }