"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useAuthStore } from "@/lib/auth/store"; import { HomeIcon, CreditCardIcon, ServerIcon, ChatBubbleLeftRightIcon, UserIcon, Bars3Icon, XMarkIcon, BellIcon, ArrowRightOnRectangleIcon, } from "@heroicons/react/24/outline"; interface DashboardLayoutProps { children: React.ReactNode; } interface NavigationChild { name: string; href: string; icon?: React.ComponentType>; } interface NavigationItem { name: string; href?: string; icon: React.ComponentType>; children?: NavigationChild[]; } const navigation = [ { name: "Dashboard", href: "/dashboard", icon: HomeIcon }, { name: "Billing", icon: CreditCardIcon, children: [ { name: "Invoices", href: "/billing/invoices" }, { name: "Payment Methods", href: "/billing/payments" }, ], }, { name: "Subscriptions", href: "/subscriptions", icon: ServerIcon }, { name: "Support", icon: ChatBubbleLeftRightIcon, children: [ { name: "Cases", href: "/support/cases" }, { name: "New Case", href: "/support/new" }, { name: "Knowledge Base", href: "/support/kb" }, ], }, { name: "Account", icon: UserIcon, children: [ { name: "Profile", href: "/account/profile" }, { name: "Security", href: "/account/security" }, { name: "Notifications", href: "/account/notifications" }, ], }, ]; export function DashboardLayout({ children }: DashboardLayoutProps) { const [sidebarOpen, setSidebarOpen] = useState(false); const [expandedItems, setExpandedItems] = useState([]); const [mounted, setMounted] = useState(false); const { user, isAuthenticated, logout, checkAuth } = useAuthStore(); const pathname = usePathname(); const router = useRouter(); useEffect(() => { setMounted(true); // Check auth on mount void checkAuth(); }, [checkAuth]); useEffect(() => { if (mounted && !isAuthenticated) { router.push("/auth/login"); } }, [mounted, isAuthenticated, router]); const toggleExpanded = (itemName: string) => { setExpandedItems(prev => prev.includes(itemName) ? prev.filter(name => name !== itemName) : [...prev, itemName] ); }; const handleLogout = () => { void logout().then(() => { router.push("/"); }); }; // Show loading state until mounted and auth is checked if (!mounted) { return (

Loading...

); } return (
{/* Mobile sidebar overlay */} {sidebarOpen && (
setSidebarOpen(false)} />
)} {/* Desktop sidebar */}
{/* Main content */}
{/* Top navigation */}

Assist Solutions Portal

{/* Notifications */} {/* Profile dropdown */}

{user?.firstName && user?.lastName ? `${user.firstName} ${user.lastName}` : user?.firstName ? user.firstName : user?.email?.split("@")[0] || "User"}

{user?.email || ""}

{/* Page content */}
{children}
); } function DesktopSidebar({ navigation, pathname, expandedItems, toggleExpanded, }: { navigation: NavigationItem[]; pathname: string; expandedItems: string[]; toggleExpanded: (name: string) => void; }) { return (
AS
Portal
); } function MobileSidebar({ navigation, pathname, expandedItems, toggleExpanded, }: { navigation: NavigationItem[]; pathname: string; expandedItems: string[]; toggleExpanded: (name: string) => void; }) { return (
AS
Portal
); } function NavigationItem({ item, pathname, isExpanded, toggleExpanded, }: { item: NavigationItem; pathname: string; isExpanded: boolean; toggleExpanded: (name: string) => void; }) { const hasChildren = item.children && item.children.length > 0; const isActive = hasChildren ? item.children?.some((child: NavigationChild) => pathname.startsWith(child.href)) || false : item.href ? pathname === item.href : false; if (hasChildren) { return (
{isExpanded && (
{item.children?.map((child: NavigationChild) => ( {child.name} ))}
)}
); } return ( {item.name} ); }