'use client'; import { useDegraded, useLive, useNow } from '@/lib/live'; /** "LIVE • updated 3 s ago" — the text ticks every second from the last real event; the data does not move. */ export function LiveIndicator({ className = '', compact = false }: { className?: string; compact?: boolean }) { const { lastEventAt, connection } = useLive((s) => ({ lastEventAt: s.lastEventAt, connection: s.connection })); const { degraded } = useDegraded(); const now = useNow(1000); const ago = lastEventAt ? Math.max(0, Math.round((now - lastEventAt) / 1000)) : null; const live = connection === 'open' && !degraded; const color = degraded ? 'var(--warn)' : connection === 'open' ? 'var(--ok)' : 'var(--ink-3)'; const word = degraded ? 'DEGRADED' : connection === 'open' ? 'LIVE' : connection === 'reconnecting' ? 'RECONNECTING' : connection === 'connecting' ? 'CONNECTING' : 'OFFLINE'; return ( {live && ago != null && ago < 2 && } {word} {!compact && ago != null && ( · updated {ago < 60 ? `${ago} s` : `${Math.floor(ago / 60)} min`} ago )} ); }