"use client"; import { useEffect, useState } from "react"; import { Menu01Icon } from "@hugeicons/core-free-icons"; import { DashboardSidebar } from "@/components/dashboard/dashboard-sidebar"; import { AppLogo } from "@/components/shared/app-logo"; import { Icon } from "@/components/shared/icon"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; const SIDEBAR_STORAGE_KEY = "courtrix_sidebar_collapsed"; type DashboardShellProps = { user: { firstName: string; lastName: string; email: string; }; children: React.ReactNode; }; export function DashboardShell({ user, children }: DashboardShellProps) { const [isDesktopCollapsed, setIsDesktopCollapsed] = useState(() => { if (typeof window === "undefined") { return false; } return window.localStorage.getItem(SIDEBAR_STORAGE_KEY) === "true"; }); const [isMobile, setIsMobile] = useState(() => { if (typeof window === "undefined") { return false; } return window.matchMedia("(max-width: 1023px)").matches; }); const [isMobileOpen, setIsMobileOpen] = useState(false); useEffect(() => { const mediaQuery = window.matchMedia("(max-width: 1023px)"); const handleViewportChange = () => { const mobile = mediaQuery.matches; setIsMobile(mobile); if (mobile) { setIsMobileOpen(false); } }; mediaQuery.addEventListener("change", handleViewportChange); return () => mediaQuery.removeEventListener("change", handleViewportChange); }, []); function toggleDesktopCollapse() { setIsDesktopCollapsed((current) => { const next = !current; window.localStorage.setItem(SIDEBAR_STORAGE_KEY, String(next)); return next; }); } return (
{/* Sidebar - placed first in DOM means it will be on the right in RTL */}
{children}
{isMobile ? (
setIsMobileOpen(false)} >
event.stopPropagation()} > setIsMobileOpen(false)} user={user} />
) : null}
); }