import type { View } from '../App'; import { Tooltip } from './ui'; import { activeStations, aggregateState, printerHint, timeAgo, shortError, usePrintStatus, worstStation } from '../lib/printStatus'; import type { PrintStation, PrintStationState } from '../lib/types'; // Pill label per aggregated state; the worst station refines error/offline text. function pillText(state: PrintStationState | 'none', station: PrintStation | null): string { if (state === 'none') return 'No printer'; if (state === 'ready') return 'Printer ready'; if (state === 'printing') return 'Printing…'; if (state === 'offline') return `Printer offline · ${timeAgo(station?.last_seen_at)}`; const err = station?.last_status?.printer?.errors?.[0]; return err ? `Printer: ${shortError(err)}` : 'Printer error'; } function tooltipContent(stations: PrintStation[]): string { return stations .map((s) => { const st = s.last_status; const roll = st?.printer?.label_id ?? 'unknown roll'; const net = st?.network; const netText = net?.ssid ? `${net.ssid}${net.ip ? ` · ${net.ip}` : ''}` : net?.state ?? 'unknown'; const hint = printerHint(s); return `${s.name} (${s.state}) — roll: ${roll} · network: ${netText} · last seen: ${timeAgo(s.last_seen_at)}${hint ? ` · ${hint}` : ''}`; }) .join('\n'); } /** * Always-visible printer status for the sidebar (desktop and mobile). The Pi * has no screen, so staff must see the printer state from every admin view. */ export function PrinterStatusPill({ onNavigate }: { onNavigate: (view: View) => void }) { const { overview } = usePrintStatus(); const stations = activeStations(overview); const state = aggregateState(stations); const station = worstStation(stations); const label = pillText(state, station); return ( {tooltipContent(stations)}}> ); }