import { useState, type ReactNode } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import { useRouterState } from '@tanstack/react-router'; import { Minimize2 } from 'lucide-react'; import { Sheet, SheetContent, SheetDescription, SheetTitle } from '@/components/ui/sheet'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Sidebar } from '@/components/layout/sidebar'; import { TopBar } from '@/components/layout/top-bar'; import { useMediaQuery } from '@/hooks/use-media-query'; import { useTheme } from '@/contexts/ThemeContext'; import { useLayout } from '@/contexts/LayoutContext'; import { useKiosk } from '@/contexts/KioskContext'; import { cn } from '@/lib/utils'; interface MainLayoutProps { status: string; onLogout: () => void; children: ReactNode; } export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const isMobile = !useMediaQuery('(min-width: 768px)'); const { appearance } = useTheme(); const customBg = appearance.background.type !== 'none'; // Framer's reducedMotion only suppresses transforms, so the always-present // width + page-transition animations need an explicit opt-out to make the // “减少动效” setting actually felt. const reduce = appearance.reduceMotion || appearance.disableMotion; const { editing } = useLayout(); const { kiosk, exit: exitKiosk } = useKiosk(); // The sidebar rests as a slim icon rail and auto-expands on hover/focus (the // peek logic below) — there's no collapse button. Two cases force it fully // expanded: layout-edit mode (the drag-to-reorder list needs room) and the // 「钉住侧栏展开」 appearance pref (operator opted out of the rail entirely). const effectiveCollapsed = !editing && !appearance.sidebarPinned; // Hover/focus peek: while collapsed, hovering (or keyboard-focusing) the rail // temporarily expands it. The rail lives in the flex flow, so the page // content is pushed right rather than overlaid. The pinned `collapsed` pref // (and the TopBar toggle that reflects it) is untouched — this is transient. const [hovered, setHovered] = useState(false); const [focused, setFocused] = useState(false); const peeking = hovered || focused; const showCollapsed = effectiveCollapsed && !peeking; const [mobileOpen, setMobileOpen] = useState(false); const pathname = useRouterState({ select: (s) => s.location.pathname }); return (