import { useState } from "react"; import { Link, useLocation } from "react-router"; import { Home, BarChart3, Settings, Wrench, Gauge, HardDrive, LogIn, ChevronRight, ChevronDown } from "lucide-react"; interface SidebarProps { collapsed: boolean; onToggle: () => void; } interface MenuItem { id: string; label: string; icon: React.ReactNode; path?: string; children?: SubMenuItem[]; } interface SubMenuItem { id: string; label: string; path: string; } const menuItems: MenuItem[] = [ { id: "home", label: "HOME", icon: , path: "/rainfall", }, { id: "graph", label: "GRAPH", icon: , path: "/graph", }, { id: "utility", label: "UTILITY", icon: , children: [ { id: "station-info", label: "Station Info", path: "/utility/station-info" }, { id: "datetime", label: "Date / Time setting", path: "/utility/datetime" }, { id: "mobile", label: "Mobile Setting", path: "/utility/mobile" }, { id: "adc", label: "ADC Setting", path: "/utility/adc" }, { id: "rainfall", label: "Rainfall Setting", path: "/utility/rainfall" }, { id: "evap", label: "EVAP Setting", path: "/utility/evap" }, { id: "gprs", label: "GPRS Setting", path: "/utility/gprs" }, { id: "level", label: "Level Setting", path: "/utility/level" }, { id: "siren", label: "SIREN Setting", path: "/utility/siren" }, { id: "network", label: "Network Setup", path: "/utility/network" }, ], }, { id: "calibration", label: "CALIBRATION", icon: , path: "/calibration", }, { id: "flash-memory", label: "FLASH MEMORY", icon: , path: "/flash-memory", }, { id: "setting", label: "SETTING", icon: , path: "/setting", }, { id: "login", label: "LOGIN", icon: , path: "/login", }, ]; export function Sidebar({ collapsed, onToggle }: SidebarProps) { const location = useLocation(); const [expandedItems, setExpandedItems] = useState>(new Set(["utility"])); const toggleExpanded = (id: string) => { const newExpanded = new Set(expandedItems); if (newExpanded.has(id)) { newExpanded.delete(id); } else { newExpanded.add(id); } setExpandedItems(newExpanded); }; const isActive = (path?: string) => { if (!path) return false; return location.pathname === path; }; const isParentActive = (children?: SubMenuItem[]) => { if (!children) return false; return children.some(child => location.pathname === child.path); }; return ( {!collapsed && MENU} {menuItems.map((item) => ( {item.children ? ( <> toggleExpanded(item.id)} className={`w-full flex items-center gap-3 px-3 py-2.5 text-sm transition-colors ${ isParentActive(item.children) ? "bg-blue-600 text-white" : "text-gray-300 hover:bg-gray-800 hover:text-white" }`} title={collapsed ? item.label : undefined} > {item.icon} {!collapsed && ( <> {item.label} > )} {!collapsed && expandedItems.has(item.id) && ( {item.children.map((child) => ( {child.label} ))} )} > ) : ( {item.icon} {!collapsed && {item.label}} )} ))} ); }