"use client" import Link from "next/link" import { usePathname } from "next/navigation" import { useRef } from "react" import type { LucideIcon } from "lucide-react" import type React from "react" import { cn } from "@/lib/utils/styles" interface NavItemProps { href: string icon: LucideIcon children: React.ReactNode onClick?: () => void } export const NavItem: React.FC = ({ href, icon: Icon, children, onClick }) => { const pathname = usePathname() const isActive = pathname === href || (href !== '/dashboard' && pathname?.startsWith(href)) const isNavigatingRef = useRef(false) const handleClick = (e: React.MouseEvent) => { // Prevent rapid double-clicks if (isNavigatingRef.current) { e.preventDefault() return } // If already on this page, just close mobile menu if needed if (isActive) { e.preventDefault() if (onClick) onClick() return } // Mark as navigating to prevent double-clicks isNavigatingRef.current = true // Call onClick handler (for mobile menu closing) - don't block navigation if (onClick) { // Use setTimeout to ensure navigation happens first setTimeout(() => onClick(), 0) } // Reset flag after navigation completes setTimeout(() => { isNavigatingRef.current = false }, 300) } return ( {children} ) }