import { useState, useCallback } from 'react'; import { Link, NavLink, useNavigate } from 'react-router-dom'; import { useAuth } from '../../contexts/AuthContext'; import { useSettings } from '../../contexts/SettingsContext'; const BASE_NAV_LINKS = [ { to: '/', label: 'Home', end: true, feature: null as null | 'forum' | 'bugs' }, { to: '/studio', label: 'Studio', end: false, feature: null }, { to: '/events', label: 'Events', end: false, feature: null }, { to: '/forum', label: 'Forum', end: false, feature: 'forum' as const }, { to: '/bugs', label: 'Bugs', end: false, feature: 'bugs' as const }, ]; export function Navbar() { const { user, isAuthenticated, logout } = useAuth(); const { forumEnabled, bugsEnabled } = useSettings(); const navigate = useNavigate(); const [menuOpen, setMenuOpen] = useState(false); const navLinks = BASE_NAV_LINKS.filter(({ feature }) => { if (feature === 'forum') return forumEnabled; if (feature === 'bugs') return bugsEnabled; return true; }); const handleLogout = useCallback(() => { logout(); setMenuOpen(false); navigate('/'); }, [logout, navigate]); const closeMenu = useCallback(() => setMenuOpen(false), []); const navLinkStyle = ({ isActive }: { isActive: boolean }): React.CSSProperties => ({ fontFamily: 'var(--font-mono)', fontSize: '0.82rem', textTransform: 'uppercase', letterSpacing: '0.12em', textDecoration: 'none', color: isActive ? 'var(--color-yellow)' : 'var(--color-text-dim)', borderBottom: isActive ? '2px solid var(--color-yellow)' : '2px solid transparent', paddingBottom: '2px', transition: 'color 0.1s, border-color 0.1s', }); return (
{/* Mobile menu */} {menuOpen && (
{navLinks.map(({ to, label, end }) => ( {label} ))} {/* Auth section */}
{isAuthenticated ? ( <> [{user?.username}] ) : ( <> Login Register )}
)}
); }