import { useState, useEffect, useRef } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { Menu, X, LogIn, LogOut, ShieldCheck, ChevronDown, Map, Bus, UserCheck, MessageCircle, Rocket, BookOpen, Wrench, Bot, Users, Code2, Trophy, Ticket, Award, GraduationCap, LayoutDashboard, Home as HomeIcon, ShieldAlert, } from 'lucide-react'; import { useAuth } from '@/context/AuthContext'; interface NavItem { label: string; path: string; icon?: any; } const PRIMARY_LINKS: NavItem[] = [ { label: 'Home', path: '/', icon: HomeIcon }, { label: 'Student dashboard', path: '/dashboard', icon: LayoutDashboard }, { label: 'Notes', path: '/notes', icon: BookOpen }, { label: 'Bus Routes', path: '/bus-routes', icon: Bus }, { label: 'Faculty Directory', path: '/faculty', icon: UserCheck }, { label: 'Community', path: '/community', icon: MessageCircle }, ]; const MORE_LINKS: NavItem[] = [ { label: 'Chatbot', path: '/ai-assistant', icon: Bot }, { label: 'Toolkit', path: '/toolkit', icon: Wrench }, { label: 'Campus Map', path: '/campus', icon: Map }, { label: 'Clubs & Centers', path: '/events', icon: Users }, { label: 'Dev Collab', path: '/collab', icon: Code2 }, { label: 'Student Leaderboard', path: '/student-leaderboard', icon: Trophy }, { label: 'Student Gate Pass', path: '/notes?portal=gatepass', icon: Ticket }, { label: 'Student Proficiency', path: '/notes?portal=proficiency', icon: Award }, ]; const ALL_MOBILE_LINKS: NavItem[] = [ ...PRIMARY_LINKS, ...MORE_LINKS, { label: 'RAISE Incubator', path: '/raise', icon: Rocket }, ]; export default function Navbar() { const [isMobileOpen, setIsMobileOpen] = useState(false); const [isProfileOpen, setIsProfileOpen] = useState(false); const [isMoreOpen, setIsMoreOpen] = useState(false); const location = useLocation(); const { user, isAuthenticated, isVerifiedStudent, isAdmin, isTransportAdmin, openAuthModal, logout } = useAuth(); const profileRef = useRef(null); const moreRef = useRef(null); useEffect(() => { setIsMobileOpen(false); setIsMoreOpen(false); }, [location.pathname]); // Close dropdowns when clicking outside useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (profileRef.current && !profileRef.current.contains(e.target as Node)) { setIsProfileOpen(false); } if (moreRef.current && !moreRef.current.contains(e.target as Node)) { setIsMoreOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const checkIsActive = (linkPath: string) => { if (linkPath === '/') return location.pathname === '/'; if (linkPath === '/notes') return location.pathname === '/notes' && !location.search.includes('portal='); if (linkPath.includes('?')) { return location.pathname + location.search === linkPath; } return location.pathname.startsWith(linkPath); }; const isMoreActive = MORE_LINKS.some((link) => checkIsActive(link.path)); return ( <> {/* Unified Floating Navbar Container */}
{/* Left: Logo & College Brand */}
rit
Rajalakshmi Institute of Technology
{/* Center: Desktop Navigation Links */}
{PRIMARY_LINKS.map((link) => { const isActive = checkIsActive(link.path); return ( {isActive && ( )} {link.label} ); })} {/* "More" Dropdown Menu */}
{isMoreOpen && ( {MORE_LINKS.map((item) => { const IconComponent = item.icon; const active = checkIsActive(item.path); return ( setIsMoreOpen(false)} className={`flex items-center gap-2.5 px-3 py-2 rounded-xl text-xs font-medium transition-all ${ active ? 'bg-white/15 text-orange-400 font-semibold' : 'text-slate-300 hover:text-white hover:bg-white/10' }`} style={{ fontFamily: 'Plus Jakarta Sans, sans-serif' }} > {IconComponent && } {item.label} ); })} )}
{/* Right: Auth Profile / Unified Sign In */}
{isAuthenticated && user ? (
{/* Profile Dropdown */} {isProfileOpen && (
{user.pictureUrl ? ( {user.name} ) : (
{isAdmin ? 'A' : user.name.charAt(0).toUpperCase()}
)}

{user.name}

{user.email}

{/* Role Badges */} {isAdmin ? (
{isTransportAdmin ? 'Transport Fleet Manager' : 'System Super Admin'}
) : isVerifiedStudent ? (
Verified Student {user.regNumber ? `(${user.regNumber})` : ''}
) : null}
{isAdmin ? ( setIsProfileOpen(false)} className="w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-slate-300 hover:text-white hover:bg-indigo-500/15 text-xs font-semibold transition-all cursor-pointer" > Admin Console ) : ( setIsProfileOpen(false)} className="w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-slate-300 hover:text-white hover:bg-orange-500/15 hover:border-orange-500/20 text-xs font-semibold transition-all cursor-pointer" > Student Dashboard )}
)}
) : ( Sign In )}
{/* Mobile Hamburger Toggle */}
setIsMobileOpen(!isMobileOpen)} className="w-9 h-9 rounded-xl flex items-center justify-center text-slate-200 hover:text-white bg-slate-800/80 border border-white/10 transition-all active:scale-95" aria-label="Toggle menu" > {isMobileOpen ? : }
{/* Mobile Menu Dropdown */} {isMobileOpen && (
{ALL_MOBILE_LINKS.map((link) => { const isActive = checkIsActive(link.path); const isRaise = link.path === '/raise'; const IconComp = link.icon; return ( setIsMobileOpen(false)} className={`px-3 py-2.5 rounded-xl text-xs font-semibold flex items-center gap-2 transition-all ${ isRaise ? 'bg-gradient-to-r from-[#EC4899] via-[#F43F5E] to-[#E11D48] text-white font-bold shadow-md shadow-pink-500/30 col-span-2 justify-center' : isActive ? 'bg-gradient-to-r from-[#FF6B00] to-[#F97316] text-white shadow-sm' : 'bg-white/5 text-slate-200 hover:bg-white/10 border border-white/5' }`} style={{ fontFamily: 'Plus Jakarta Sans, sans-serif' }} > {IconComp && } {link.label} ); })}
{/* Mobile Auth Button */}
{!isAuthenticated ? ( ) : (
{user?.name} {isAdmin ? 'Admin' : (user?.regNumber || 'Student')}
{isAdmin ? ( setIsMobileOpen(false)} className="w-full flex items-center justify-center gap-2 px-4 py-2 rounded-xl bg-indigo-600 text-white text-xs font-bold" > Go to Admin Console ) : ( setIsMobileOpen(false)} className="w-full flex items-center justify-center gap-2 px-4 py-2 rounded-xl bg-orange-500 text-white text-xs font-bold" > Go to Student Dashboard )}
)}
)}
{/* Floating RAISE Incubator Button directly below right side of navbar */} RAISE Incubator
{/* Spacer to prevent content overlap */}
); }