import { useState } from "react"; import { HomeOutlined, FolderOutlined, FileTextOutlined, SettingOutlined, DownOutlined, RightOutlined, SearchOutlined, } from "@ant-design/icons"; import { NAV_TREE, type NavNode } from "@/utils/data"; interface Props { activeNodeId: string; onNodeClick: (node: NavNode) => void; } const iconFor = (icon?: string) => { switch (icon) { case "home": return ; case "doc": return ; case "settings": return ; default: return ; } }; export default function Sidebar({ activeNodeId, onNodeClick }: Props) { const [expanded, setExpanded] = useState>({ kpi: true, quote: true, sys: true, }); const [query, setQuery] = useState(""); const toggle = (id: string) => setExpanded((s) => ({ ...s, [id]: !s[id] })); const renderNode = (node: NavNode, depth: number): React.ReactNode => { const hasChildren = !!(node.children && node.children.length); const isOpen = !!expanded[node.id]; const active = node.id === activeNodeId; if (query && !node.label.toLowerCase().includes(query.toLowerCase()) && !hasChildren) { return null; } return (
{ if (hasChildren) toggle(node.id); onNodeClick(node); }} style={{ display: "flex", alignItems: "center", gap: 6, paddingLeft: 8 + depth * 14, paddingRight: 8, height: 26, fontSize: 12, cursor: "pointer", color: active ? "var(--accent-strong)" : "var(--text)", background: active ? "var(--selected)" : "transparent", borderLeft: active ? "2px solid var(--accent)" : "2px solid transparent", fontWeight: active ? 500 : 400, }} onMouseEnter={(e) => { if (!active) e.currentTarget.style.background = "var(--bg-row-hover)"; }} onMouseLeave={(e) => { if (!active) e.currentTarget.style.background = "transparent"; }} > {hasChildren ? ( isOpen ? ( ) : ( ) ) : null} {iconFor(node.icon)} {node.label} {node.badge && ( {node.badge} )}
{hasChildren && isOpen && (
{node.children!.map((c) => renderNode(c, depth + 1))}
)}
); }; return (
setQuery(e.target.value)} placeholder="ๆœ็ดข่œๅ•" style={{ flex: 1, height: 22, border: "1px solid var(--border-input)", background: "var(--bg-input)", padding: "0 6px", fontSize: 12, outline: "none", fontFamily: "inherit", }} />
{NAV_TREE.map((n) => renderNode(n, 0))}
); }