'use client'; import { User } from '@/prisma/generated/client'; import { HomeIcon, Squares2X2Icon, ShieldCheckIcon, ShareIcon, GlobeAltIcon, StarIcon, ClockIcon, DocumentTextIcon, ChevronDownIcon, } from '@heroicons/react/24/outline'; import * as Accordion from '@radix-ui/react-accordion'; import type { QuickLink } from '@/app/(authenticated)/lib/actions'; import Link from 'next/link'; import { usePathname, useSearchParams } from 'next/navigation'; import { motion, AnimatePresence } from 'framer-motion'; import { FAST } from '@/lib/motion'; import { cn } from '@/lib/utils'; import { useTranslations } from 'next-intl'; interface NavBarProps { user: User; isCollapsed?: boolean; quickLinks?: QuickLinks; } export type QuickLinks = { favorites: QuickLink[]; recent: QuickLink[] }; export default function NavBar({ user, isCollapsed = false, quickLinks, }: NavBarProps) { const t = useTranslations('Navigation'); const path = usePathname() || '/'; const searchParams = useSearchParams(); const adminPattern = /^\/admin\/?$/; const homePattern = /^\/$/; const boardPattern = /^\/boards(\/[a-zA-Z0-9_-]+)?\/?$/; const notePattern = /^\/boards\/[a-zA-Z0-9_-]+\/notes(\/[a-zA-Z0-9_-]+)?\/?$/; const isCommunityNote = notePattern.test(path) && searchParams.get('ref') === 'community'; const navItems = [ { name: t('home'), href: '/', icon: HomeIcon, active: homePattern.test(path), }, { name: t('boards'), href: '/boards', icon: Squares2X2Icon, active: !isCommunityNote && (boardPattern.test(path) || notePattern.test(path)), }, // Collapsed sidebar hides the quick-link accordions, so expose their pages as icons. ...(isCollapsed ? [ { name: t('favorites'), href: '/favorites', icon: StarIcon, active: path.startsWith('/favorites'), }, { name: t('recent'), href: '/recent', icon: ClockIcon, active: path.startsWith('/recent'), }, ] : []), { name: t('shared'), href: '/shared', icon: ShareIcon, active: path.startsWith('/shared'), }, { name: t('community'), href: '/community', icon: GlobeAltIcon, active: path.startsWith('/community') || isCommunityNote, }, ]; if (user?.role === 'admin') { navItems.push({ name: t('admin'), href: '/admin', icon: ShieldCheckIcon, active: adminPattern.test(path), }); } return ( ); }