'use client'; import { useState, useRef, FocusEvent } from 'react'; import { FiMenu, FiX, FiHome, FiFileText, FiFile, FiUser, FiMail, FiMapPin, FiFeather, FiTag, FiServer, FiCpu, FiList, FiChevronDown } from 'react-icons/fi'; import Link from 'next/link'; export type IconKey = | 'home' | 'blog' | 'file' | 'user' | 'contact' | 'location' | 'pen' | 'tags' | 'server' | 'device' | 'menu'; const ICON_MAP: Record = { home: FiHome, blog: FiFileText, file: FiFile, user: FiUser, contact: FiMail, location: FiMapPin, pen: FiFeather, tags: FiTag, server: FiServer, device: FiCpu, menu: FiList }; export interface NavLinkItem { key: string; href?: string; label: string; iconKey: IconKey; children?: NavLinkItem[]; } interface NavMenuProps { items: NavLinkItem[]; } export function NavMenu({ items }: NavMenuProps) { const [open, setOpen] = useState(false); const [activeDropdown, setActiveDropdown] = useState(null); const closeTimer = useRef(null); const toggle = () => setOpen((val) => !val); const close = () => setOpen(false); const handleBlur = (event: FocusEvent) => { if (!event.currentTarget.contains(event.relatedTarget as Node)) { setActiveDropdown(null); } }; const clearCloseTimer = () => { if (closeTimer.current) { clearTimeout(closeTimer.current); closeTimer.current = null; } }; const openDropdown = (key: string) => { clearCloseTimer(); setActiveDropdown(key); }; const scheduleCloseDropdown = () => { clearCloseTimer(); closeTimer.current = window.setTimeout(() => setActiveDropdown(null), 180); }; const renderChild = (item: NavLinkItem) => { const Icon = ICON_MAP[item.iconKey] ?? FiFile; return item.href ? ( {item.label} ) : null; }; return (
); }