"use client" import { useAuth } from "@/contexts/auth-context" import Link from "next/link" import { usePathname } from "next/navigation" import { Button } from "@/components/ui/button" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { Badge } from "@/components/ui/badge" import { Bell, Settings, LogOut, User, Shield, ArrowLeft, LayoutDashboard, Files, Zap, Users, BarChart3, FileText, Cog, HelpCircle, ChevronLeft, ChevronRight } from "lucide-react" import { useState } from "react" import { AdminNotificationsPanel } from "@/components/admin/admin-notifications-panel" import { useAdminNotifications } from "@/contexts/AdminNotificationContext" import { cn } from "@/lib/utils" interface AdminSidebarLayoutProps { children: React.ReactNode } interface SidebarItem { id: string label: string icon: React.ComponentType<{ className?: string }> href?: string badge?: number subItems?: SidebarItem[] } export function AdminSidebarLayout({ children }: AdminSidebarLayoutProps) { const [isLoggingOut, setIsLoggingOut] = useState(false) const [showNotifications, setShowNotifications] = useState(false) const [sidebarCollapsed, setSidebarCollapsed] = useState(false) const pathname = usePathname() const { user, logout, isAdmin } = useAuth() const { unreadCount } = useAdminNotifications() // Handle logout with loading state const handleLogout = async () => { try { setIsLoggingOut(true) await logout() } catch (error) { console.error('Logout failed:', error) setIsLoggingOut(false) } } // Sidebar navigation items const sidebarItems: SidebarItem[] = [ { id: "dashboard", label: "Dashboard", icon: LayoutDashboard, href: "/admin" }, { id: "features", label: "Custom Features", icon: Zap, href: "/admin?tab=features", badge: 0 // This will be updated dynamically }, { id: "templates", label: "Templates", icon: Files, href: "/admin/templates" }, { id: "users", label: "User Management", icon: Users, href: "/admin/users" }, { id: "analytics", label: "Analytics", icon: BarChart3, href: "/admin/analytics" }, { id: "settings", label: "Settings", icon: Cog, href: "/admin/settings" }, { id: "help", label: "Help & Support", icon: HelpCircle, href: "/admin/help" } ] // Redirect non-admin users if (!isAdmin) { return (

Access Denied

You don't have permission to access the admin panel.

) } const SidebarItem = ({ item, level = 0 }: { item: SidebarItem; level?: number }) => { const [isExpanded, setIsExpanded] = useState(false) const hasSubItems = item.subItems && item.subItems.length > 0 const isActive = pathname === item.href || (item.href && pathname.startsWith(item.href)) return (
{ e.preventDefault() setIsExpanded(!isExpanded) } : undefined} className={cn( "flex items-center justify-between w-full px-3 py-2 text-sm rounded-lg transition-colors", level > 0 && "ml-4 pl-6", isActive ? "bg-orange-500 text-black font-medium" : "text-white/80 hover:bg-white/10 hover:text-white", sidebarCollapsed && level === 0 && "justify-center px-2" )} >
{(!sidebarCollapsed || level > 0) && ( {item.label} )}
{!sidebarCollapsed && (
{item.badge !== undefined && item.badge > 0 && ( {item.badge} )} {hasSubItems && ( )}
)} {hasSubItems && isExpanded && !sidebarCollapsed && (
{item.subItems!.map((subItem) => ( ))}
)}
) } return (
{/* Sidebar */}
{/* Sidebar Header */}
{!sidebarCollapsed && (
C
Admin Panel
)}
{/* Navigation */} {/* Sidebar Footer */}
{!sidebarCollapsed ? (
{(user?.username && user.username.charAt(0)) || (user?.email && user.email.charAt(0)) || "U"}

{user?.username || user?.email || "User"}

Administrator

) : (
{(user?.username && user.username.charAt(0)) || (user?.email && user.email.charAt(0)) || "U"}
)}
{/* Main Content */}
{/* Top Header */}
{/* Back to Main Site */}
Back to Site
{/* Right side */}
{/* Notifications */} {/* User Menu */} {user && user.email && (

{user.username || user.email || "User"}

{user.email || "No email"}

Admin
Profile Settings {isLoggingOut ? "Logging out..." : "Log out"}
)}
{/* Main Content Area */}
{children}
{/* Notifications Panel */}
) }