import { useEffect, useState } from 'react'; import { Menu, Moon, Sun } from 'lucide-react'; import type { HealthStatus, RadioConfig } from '../types'; import { api } from '../api'; import { toast } from './ui/sonner'; import { handleKeyboardActivate } from '../utils/a11y'; import { applyTheme, getSavedTheme, THEME_CHANGE_EVENT } from '../utils/theme'; import { cn } from '@/lib/utils'; interface StatusBarProps { health: HealthStatus | null; config: RadioConfig | null; settingsMode?: boolean; onSettingsClick: () => void; onMenuClick?: () => void; } export function StatusBar({ health, config, settingsMode = false, onSettingsClick, onMenuClick, }: StatusBarProps) { const radioState = health?.radio_state ?? (health?.radio_initializing ? 'initializing' : health?.radio_connected ? 'connected' : 'disconnected'); const connected = health?.radio_connected ?? false; const statusLabel = radioState === 'paused' ? 'Radio Paused' : radioState === 'connecting' ? 'Radio Connecting' : radioState === 'initializing' ? 'Radio Initializing' : connected ? 'Radio OK' : 'Radio Disconnected'; const [reconnecting, setReconnecting] = useState(false); const [currentTheme, setCurrentTheme] = useState(getSavedTheme); useEffect(() => { const handleThemeChange = (event: Event) => { const themeId = (event as CustomEvent).detail; setCurrentTheme(typeof themeId === 'string' && themeId ? themeId : getSavedTheme()); }; window.addEventListener(THEME_CHANGE_EVENT, handleThemeChange as EventListener); return () => { window.removeEventListener(THEME_CHANGE_EVENT, handleThemeChange as EventListener); }; }, []); const handleReconnect = async () => { setReconnecting(true); try { const result = await api.reconnectRadio(); if (result.connected) { toast.success('Reconnected', { description: result.message }); } } catch (err) { toast.error('Reconnection failed', { description: err instanceof Error ? err.message : 'Check radio connection and power', }); } finally { setReconnecting(false); } }; const handleThemeToggle = () => { const nextTheme = currentTheme === 'light' ? 'original' : 'light'; applyTheme(nextTheme); setCurrentTheme(nextTheme); }; return (
{/* Mobile menu button - only visible on small screens */} {onMenuClick && ( )}

RemoteTerm

{config && (
{config.name || 'Unnamed'} { navigator.clipboard.writeText(config.public_key); toast.success('Public key copied!'); }} title="Click to copy public key" aria-label="Copy public key" > {config.public_key.toLowerCase()}
)} {(radioState === 'disconnected' || radioState === 'paused') && ( )}
); }