'use client'; import { useState } from 'react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import { useQuery } from '@tanstack/react-query'; import { useAuthStore } from '@/store/authStore'; import { versionApi } from '@/lib/api'; import { BrandMark } from '@/components/BrandMark'; import { LayoutDashboard, Mail, Settings, LogOut, Menu, X, User, Shield, Users, CreditCard, Bell, Inbox, Activity } from 'lucide-react'; interface DashboardLayoutProps { children: React.ReactNode; } export function DashboardLayout({ children }: DashboardLayoutProps) { const [sidebarOpen, setSidebarOpen] = useState(false); const pathname = usePathname(); const router = useRouter(); const { user, logout } = useAuthStore(); const { data: versionInfo } = useQuery({ queryKey: ['version'], queryFn: () => versionApi.get(), staleTime: Infinity, }); const handleLogout = () => { logout(); router.push('/login'); }; const navigation = [ { name: 'Dashboard', href: '/dashboard', icon: LayoutDashboard }, { name: 'Mail Accounts', href: '/accounts', icon: Mail }, { name: 'Notifications', href: '/notifications', icon: Bell }, { name: 'Mailbox Activity', href: '/logs', icon: Inbox }, { name: 'Settings', href: '/settings', icon: Settings }, ]; const adminNavigation = user?.is_superuser ? [ { name: 'Admin Overview', href: '/admin', icon: Shield }, { name: 'Manage Users', href: '/admin/users', icon: Users }, { name: 'Manage Plans', href: '/admin/plans', icon: CreditCard }, { name: 'Activity Logs', href: '/admin/logs', icon: Activity }, ] : []; const allNavItems = [...navigation, ...adminNavigation]; return (
{/* Sidebar for desktop */}
{/* Mobile sidebar */} {sidebarOpen && (
setSidebarOpen(false)} />
)} {/* Main content */}
{/* Top bar */}

{allNavItems.find((item) => item.href === pathname)?.name || 'Dashboard'}

{user?.is_superuser ? : }

{user?.full_name}

{user?.email} {user?.is_superuser && ( Admin )}

{/* Page content */}
{children}
{/* Footer */}
); }