'use client' import { usePathname } from 'next/navigation' import { useEffect, useState } from 'react' import { authFetch, getApiBase, getToken } from '../lib/auth' type NavigationItem = { href: string label: string shortLabel: string icon: 'dashboard' | 'media' | 'issues' | 'invites' | 'settings' | 'stats' adminOnly?: boolean match: (path: string) => boolean } const NAVIGATION: NavigationItem[] = [ { href: '/insights', label: 'My Stats', shortLabel: 'Stats', icon: 'stats', match: (path) => path === '/insights' }, { href: '/', label: 'My Requests', shortLabel: 'Requests', icon: 'dashboard', match: (path) => path === '/' || path.startsWith('/requests/') }, { href: '/new-requests', label: 'New Request', shortLabel: 'New', icon: 'media', match: (path) => path === '/new-requests' }, { href: '/portal/issues', label: 'Issues', shortLabel: 'Issues', icon: 'issues', match: (path) => path.startsWith('/portal/issues') }, { href: '/profile/invites', label: 'Invites', shortLabel: 'Invites', icon: 'invites', match: (path) => path.startsWith('/profile/invites') }, { href: '/admin', label: 'Configuration', shortLabel: 'Config', icon: 'settings', adminOnly: true, match: (path) => path.startsWith('/admin') || path.startsWith('/users') }, ] const HIDDEN_ROUTES = ['/login', '/signup', '/forgot-password', '/reset-password', '/how-it-works'] function NavigationIcon({ name }: { name: NavigationItem['icon'] }) { const paths: Record = { stats: <>, dashboard: <>, media: <>, issues: <>, invites: <>, settings: <>, } return } export default function WorkspaceNavigation() { const pathname = usePathname() const [role, setRole] = useState(null) const [ready, setReady] = useState(false) const [showRequestsNav, setShowRequestsNav] = useState(true) useEffect(() => { const token = getToken() if (!token) { setReady(true) return } Promise.all([ authFetch(`${getApiBase()}/auth/me`), fetch(`${getApiBase()}/site/public`).catch(() => null), ]) .then(async ([response, siteResponse]) => { if (response.ok) setRole((await response.json())?.role ?? 'user') if (siteResponse?.ok) setShowRequestsNav((await siteResponse.json())?.navigation?.showRequests !== false) }) .catch(() => undefined) .finally(() => setReady(true)) }, []) if (!ready || !getToken() || HIDDEN_ROUTES.some((route) => pathname.startsWith(route))) { return null } const items = NAVIGATION.filter((item) => (!item.adminOnly || role === 'admin') && (showRequestsNav || item.href !== '/new-requests')) return ( <> ) }