import { useState } from 'react'; import { LogOut, Monitor } from 'lucide-react'; import { motion, AnimatePresence } from 'motion/react'; import { useRouterState } from '@tanstack/react-router'; import { IconMorph } from '@/components/interior/icon-morph'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ThemeToggle } from '@/components/theme-toggle'; import { ConfirmDialog } from '@/components/confirm-dialog'; import { NAV_ITEMS } from '@/components/layout/sidebar'; import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; import { useKiosk } from '@/contexts/KioskContext'; // Toggleable top-bar elements (the menu/title/logout are essential and always // render). Labels drive the settings toggles; ids match `topbarItems`. export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [ { id: 'status', label: '连接状态徽章' }, { id: 'theme', label: '主题切换按钮' }, { id: 'kiosk', label: '展示模式按钮' }, ]; interface TopBarProps { status: string; mobileOpen: boolean; onMobileOpenChange: (open: boolean) => void; onLogout: () => void; isMobile: boolean; } export function TopBar({ status, mobileOpen, onMobileOpenChange, onLogout, isMobile, }: TopBarProps) { const [confirmLogout, setConfirmLogout] = useState(false); const pathname = useRouterState({ select: (s) => s.location.pathname }); const meta = NAV_ITEMS.find((n) => n.to === pathname); const PageIcon = meta?.icon; const online = status === '已连接'; // Which optional top-bar elements the operator has kept (reconciled against // the live catalogue, so a new element defaults to shown). const { topbarItems } = useLayout(); const { enter: enterKiosk } = useKiosk(); const shown = new Set( reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id)) .filter((i) => i.visible) .map((i) => i.id), ); return (
{/* Mobile-only menu trigger. On desktop there's no collapse button — the sidebar auto-expands on hover/focus, and its boundary with the content is a soft surface-tone shift, not a hard border. */} {isMobile && ( onMobileOpenChange(index === 1)} className="ui-button ui-button-icon topbar-control cursor-pointer border-0 bg-transparent text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:ring-[3px] focus-visible:ring-ring/40 dark:border-0 dark:bg-transparent dark:text-foreground dark:focus-visible:ring-ring/40" /> )} {/* Page title */} {PageIcon && }

{meta?.label}

{meta?.description}
{shown.has('status') && ( {status} )} {shown.has('theme') && } {shown.has('kiosk') && ( )}
); }