"use client"; import { signOut, useSession } from "next-auth/react"; import Link from "next/link"; import { usePathname } from "next/navigation"; export default function AdminLayout({ children, }: { children: React.ReactNode; }) { const pathname = usePathname(); const { data: session } = useSession(); const userRole = (session?.user as any)?.role; const username = session?.user?.name || ''; const isAdmin = userRole === 'ADMIN'; const isSuperAdmin = username === 'admin'; const allNavigation = [ { name: "Dashboard", href: "/admin", roles: ['ADMIN', 'VIEWER'], superAdminOnly: false }, { name: "Devices", href: "/admin/devices", roles: ['ADMIN', 'VIEWER'], superAdminOnly: false }, { name: "MQTT Provisioning", href: "/admin/mqtt", roles: ['ADMIN'], superAdminOnly: false }, { name: "Setup Guide", href: "/admin/setup", roles: ['ADMIN', 'VIEWER'], superAdminOnly: false }, { name: "Users", href: "/admin/users", roles: ['ADMIN'], superAdminOnly: false }, { name: "Settings", href: "/admin/settings", roles: ['ADMIN'], superAdminOnly: true }, { name: "Emails", href: "/admin/emails", roles: ['ADMIN'], superAdminOnly: true }, ]; // Filter navigation based on user role and super admin status const navigation = allNavigation.filter(item => { const hasRole = item.roles.includes(userRole as string); const hasAccess = item.superAdminOnly ? isSuperAdmin : true; return hasRole && hasAccess; }); return (