import { Link, useLocation } from 'react-router-dom' import type { LucideIcon } from 'lucide-react' import { cn } from '@/lib/utils' import { prefetchForRoute } from '@/lib/routePrefetch' interface NavSubItem { href: string label: string count?: number isActive?: boolean } interface NavItemProps { href: string icon: LucideIcon label: string badge?: number | 'dot' iconColor?: string matchPaths?: string[] collapsed?: boolean children?: NavSubItem[] } export function NavItem({ href, icon: Icon, label, badge, iconColor, matchPaths, collapsed, children }: NavItemProps) { const location = useLocation() const fullPath = location.pathname + location.search const isActive = matchPaths ? matchPaths.some(p => location.pathname.startsWith(p)) : href === '/' ? location.pathname === '/' : location.pathname.startsWith(href) // Check if any child is specifically active const activeChild = children?.find(c => fullPath === c.href || fullPath.startsWith(c.href + '&')) const isParentDimmed = !!activeChild && isActive if (collapsed) { return ( prefetchForRoute(href)} className={cn( 'group relative flex items-center justify-center rounded-lg p-2 transition-all duration-120', isActive ? 'bg-[var(--sidebar-active)] text-foreground' : 'text-muted-foreground hover:bg-[var(--sidebar-hover)] hover:text-foreground' )} title={label} > {isActive && (
)}