"use client"; import { ReactNode, useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { Avatar, Box, Button, Divider, Drawer, List, ListItemButton, ListItemIcon, ListItemText, Stack, Typography, useTheme, useMediaQuery, IconButton } from "@mui/material"; import MenuIcon from "@mui/icons-material/Menu"; import DashboardIcon from "@mui/icons-material/Dashboard"; import SwapHorizIcon from "@mui/icons-material/SwapHoriz"; import BarChartIcon from "@mui/icons-material/BarChart"; import VpnKeyIcon from "@mui/icons-material/VpnKey"; import SecurityIcon from "@mui/icons-material/Security"; import SettingsIcon from "@mui/icons-material/Settings"; import HistoryIcon from "@mui/icons-material/History"; import GppBadIcon from "@mui/icons-material/GppBad"; import LogoutIcon from "@mui/icons-material/Logout"; type User = { id: string; name?: string | null; email?: string | null; image?: string | null; }; const NAV_ITEMS = [ { href: "/", label: "Overview", icon: DashboardIcon }, { href: "/proxy-hosts", label: "Proxy Hosts", icon: SwapHorizIcon }, { href: "/analytics", label: "Analytics", icon: BarChartIcon }, { href: "/access-lists", label: "Access Lists", icon: VpnKeyIcon }, { href: "/certificates", label: "Certificates", icon: SecurityIcon }, { href: "/settings", label: "Settings", icon: SettingsIcon }, { href: "/audit-log", label: "Audit Log", icon: HistoryIcon }, { href: "/waf-events", label: "WAF Events", icon: GppBadIcon } ] as const; const DRAWER_WIDTH = 260; export default function DashboardLayoutClient({ user, children }: { user: User; children: ReactNode }) { const [mobileOpen, setMobileOpen] = useState(false); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("md")); const pathname = usePathname(); const router = useRouter(); const handleDrawerToggle = () => { setMobileOpen(!mobileOpen); }; const drawerContent = ( Caddy Proxy Manager {NAV_ITEMS.map((item) => { const selected = pathname === item.href; const Icon = item.icon; return ( isMobile && setMobileOpen(false)} sx={{ mb: 0.5, borderRadius: 3, color: selected ? "primary.contrastText" : "text.secondary", "& .MuiListItemIcon-root": { color: selected ? "inherit" : "text.secondary", minWidth: 40, }, }} > ); })} { if (isMobile) setMobileOpen(false); router.push("/profile"); }} sx={{ gap: 2, px: 1, mb: 2, py: 1, borderRadius: 1, color: "text.primary" }} > {(user.name?.[0] || "U").toUpperCase()} {user.name || "Administrator"} {user.email}
); return ( {isMobile && ( )} {drawerContent} {children} ); }