'use client'; import { useEffect, useState } from 'react'; import { useRouter, usePathname } from 'next/navigation'; import Link from 'next/link'; import { AppShell, AppShellSkipLink, AppShellMobileToggle, AppShellOverlay, AppShellSidebar, AppShellNav, AppShellNavItem, AppShellMain, Button, } from '@/components/ui/Primitives'; import { useAuth } from '@/lib/auth-context'; import { useTheme } from '@/lib/theme-context'; import { ProductSwitcher } from '@/components/product-switcher'; import { SystemBanners } from '@/components/system-banners'; const NAV_ITEMS = [ { href: '/dashboard', label: 'Overview' }, { href: '/dashboard/items', label: 'Items' }, { href: '/dashboard/board', label: 'Board' }, { href: '/dashboard/fleet', label: 'Fleet' }, { href: '/dashboard/settings', label: 'Settings' }, ]; /** Open the ⌘K command palette by replaying the global hotkey. */ function openCommandPalette() { window.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', metaKey: true, ctrlKey: true })); } export default function DashboardLayout({ children }: { children: React.ReactNode }) { const { user, loading, logout } = useAuth(); const { theme, setTheme } = useTheme(); const router = useRouter(); const pathname = usePathname(); const [navOpen, setNavOpen] = useState(false); useEffect(() => { if (!loading && !user) { router.replace('/login'); } }, [user, loading, router]); if (loading || !user) { return (