'use client' import { useState } from 'react' import Link from 'next/link' import type { Route } from 'next' import { usePathname } from 'next/navigation' import { signOut } from 'next-auth/react' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { Separator } from '@/components/ui/separator' import { LayoutDashboard, FolderKanban, Users, ClipboardList, Settings, FileSpreadsheet, Menu, X, LogOut, ChevronRight, BookOpen, Handshake, History, Trophy, User, MessageSquare, LayoutTemplate, Medal, } from 'lucide-react' import { getInitials } from '@/lib/utils' import { Logo } from '@/components/shared/logo' import { EditionSelector } from '@/components/shared/edition-selector' import { useEdition } from '@/contexts/edition-context' import { UserAvatar } from '@/components/shared/user-avatar' import { NotificationBell } from '@/components/shared/notification-bell' import { useSession } from 'next-auth/react' import { trpc } from '@/lib/trpc/client' interface AdminSidebarProps { user: { name?: string | null email?: string | null role?: string } } type NavItem = { name: string href: string icon: typeof LayoutDashboard activeMatch?: string // pathname must include this to be active activeExclude?: string // pathname must NOT include this to be active subItems?: { name: string; href: string }[] } // Main navigation - scoped to selected edition const navigation: NavItem[] = [ { name: 'Dashboard', href: '/admin', icon: LayoutDashboard, }, { name: 'Competitions', href: '/admin/competitions', icon: Medal, }, { name: 'Awards', href: '/admin/awards', icon: Trophy, }, { name: 'Projects', href: '/admin/projects', icon: ClipboardList, }, { name: 'Members', href: '/admin/members', icon: Users, }, { name: 'Reports', href: '/admin/reports', icon: FileSpreadsheet, }, { name: 'Learning Hub', href: '/admin/learning', icon: BookOpen, }, { name: 'Messages', href: '/admin/messages', icon: MessageSquare, }, { name: 'Partners', href: '/admin/partners', icon: Handshake, }, ] // Admin-only navigation const adminNavigation: NavItem[] = [ { name: 'Manage Editions', href: '/admin/programs', icon: FolderKanban, activeExclude: 'apply-settings', }, { name: 'Apply Page', href: '/admin/programs', icon: LayoutTemplate, activeMatch: 'apply-settings', }, { name: 'Audit Log', href: '/admin/audit', icon: History, }, { name: 'Settings', href: '/admin/settings', icon: Settings, }, ] // Role display labels const roleLabels: Record = { SUPER_ADMIN: 'Super Admin', PROGRAM_ADMIN: 'Program Admin', JURY_MEMBER: 'Jury Member', OBSERVER: 'Observer', } export function AdminSidebar({ user }: AdminSidebarProps) { const pathname = usePathname() const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) const { status: sessionStatus } = useSession() const isAuthenticated = sessionStatus === 'authenticated' const { data: avatarUrl } = trpc.avatar.getUrl.useQuery(undefined, { enabled: isAuthenticated, }) const { currentEdition } = useEdition() const isSuperAdmin = user.role === 'SUPER_ADMIN' const roleLabel = roleLabels[user.role || ''] || 'User' // Build dynamic admin nav with current edition's apply page const dynamicAdminNav = adminNavigation.map((item) => { if (item.name === 'Apply Page' && currentEdition?.id) { return { ...item, href: `/admin/programs/${currentEdition.id}/apply-settings` } } return item }) return ( <> {/* Mobile menu button */}
{/* Mobile menu overlay */} {isMobileMenuOpen && (
setIsMobileMenuOpen(false)} /> )} {/* Sidebar */} ) }