import { type ReactNode } from 'react'; import { Clock, Download, Gauge, MessageSquare, RefreshCw, Settings, } from 'lucide-react'; import { type DashboardOverview, type StatusSnapshot } from './api'; import { type Messages } from './i18n'; export type DashboardView = 'usage' | 'rooms' | 'scheduled' | 'settings'; export type DashboardFreshness = 'fresh' | 'stale' | 'offline'; interface DashboardNavData { overview: DashboardOverview; snapshots: StatusSnapshot[]; } const NAV_ICONS: Record = { usage: , rooms: , scheduled: , settings: , }; function navItems(t: Messages) { return [ { href: '#/rooms', label: t.nav.rooms, view: 'rooms' as const }, { href: '#/scheduled', label: t.nav.scheduled, view: 'scheduled' as const }, { href: '#/usage', label: t.nav.usage, view: 'usage' as const }, { href: '#/settings', label: t.nav.settings, view: 'settings' as const }, ]; } function navStats(data: DashboardNavData | null) { if (!data) return null; const queue = data.snapshots.reduce( (acc, snapshot) => { for (const entry of snapshot.entries) { if (entry.status === 'processing') acc.processing += 1; } return acc; }, { processing: 0 }, ); return { processing: queue.processing, }; } function navBadge( view: DashboardView, stats: ReturnType, ): number | null { if (view === 'rooms' && stats && stats.processing > 0) { return stats.processing; } return null; } function pwaStateLabel({ installed, offlineReady, secureContext, t, }: { installed: boolean; offlineReady: boolean; secureContext: boolean; t: Messages; }) { if (!secureContext) return t.pwa.secureRequired; if (installed) return t.pwa.installed; if (offlineReady) return t.pwa.ready; return t.pwa.app; } function DashboardBrandLink({ onNavigate, }: { onNavigate: (view: DashboardView) => void; }) { return ( onNavigate('rooms')} title="EJClaw" > EJ ); } function DashboardNavLinks({ activeView, data, onAfterNavigate, onNavigate, t, }: { activeView: DashboardView; data: DashboardNavData | null; onAfterNavigate?: () => void; onNavigate: (view: DashboardView) => void; t: Messages; }) { const stats = navStats(data); return ( ); } function DashboardNavActions({ canInstall, installed, offlineReady, onInstall, onRefresh, online, refreshing, secureContext, t, }: { canInstall: boolean; installed: boolean; offlineReady: boolean; onInstall: () => void; onRefresh: () => void; online: boolean; refreshing: boolean; secureContext: boolean; t: Messages; }) { const pwaState = pwaStateLabel({ installed, offlineReady, secureContext, t }); const status = `${online ? t.pwa.online : t.pwa.offline} ยท ${pwaState}`; return (
{status}
{canInstall ? ( ) : null}
); } export function SideRail({ activeView, canInstall, data, installed, offlineReady, onInstall, onNavigate, onRefresh, online, refreshing, secureContext, t, }: { activeView: DashboardView; canInstall: boolean; data: DashboardNavData | null; installed: boolean; offlineReady: boolean; onInstall: () => void; onNavigate: (view: DashboardView) => void; onRefresh: () => void; online: boolean; refreshing: boolean; secureContext: boolean; t: Messages; }) { return ( ); } export function SectionNav({ activeView, canInstall, data, drawerOpen, freshness, freshnessText, installed, onCloseDrawer, onInstall, onNavigate, onOpenDrawer, offlineReady, onRefresh, online, refreshing, secureContext, t, }: { activeView: DashboardView; canInstall: boolean; data: DashboardNavData | null; drawerOpen: boolean; freshness: DashboardFreshness; freshnessText: string; installed: boolean; onCloseDrawer: () => void; onInstall: () => void; onNavigate: (view: DashboardView) => void; onOpenDrawer: () => void; offlineReady: boolean; onRefresh: () => void; online: boolean; refreshing: boolean; secureContext: boolean; t: Messages; }) { const activeLabel = navItems(t).find((item) => item.view === activeView)?.label ?? t.nav.rooms; return ( <> {drawerOpen ? ( <> ) : null} ); }