"use client"; import { useState } from "react"; import Sublink, { GroupAccordionProvider } from "./Sublink"; import SidebarGroupHeader from "./SidebarGroupHeader"; import type { DocuRoute } from "../node/types"; import { cn } from "../node/utils"; import { config as docuConfig } from "../node/client-routes"; interface MenuProps { onNavigate?: () => void; className?: string; pathname?: string; routes?: DocuRoute[]; } function getCurrentContext(path: string): string | undefined { if (!path.startsWith("/docs")) return undefined; const match = path.match(/^\/docs\/([^/]+)/); return match ? match[1] : undefined; } function getContextRoute(contextPath: string, routeList: DocuRoute[]): DocuRoute | undefined { return routeList.find((route) => { const normalizedHref = route.href.replace(/^\/+|\/+$/, ""); return normalizedHref === contextPath; }); } export default function Menu({ onNavigate, className = "", pathname, routes = [] }: MenuProps) { const menuRoutes = routes; const [currentPath] = useState( () => pathname || (typeof window !== "undefined" ? window.location.pathname : "/docs") ); if (!currentPath.startsWith("/docs")) return null; const mode = docuConfig.sidebar?.context || "dropdown"; const navProps = { "aria-label": "Documentation navigation" as const, className: cn("transition-all duration-200", className), }; // Shared nav item with border-left overlap wrapper const renderBorderItem = (item: DocuRoute, parentRouteHref: string, key: string) => { const fullHref = `/docs${parentRouteHref}${item.href}`; const isActive = currentPath === fullHref || currentPath === `${fullHref}.html`; return (