import type { ReactNode } from "react";
import { Link } from "react-router-dom";
import { ChevronRight } from "lucide-react";
import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenuButton, SidebarMenuItem, SidebarMenu, SidebarMenuSub, SidebarMenuSubItem, SidebarMenuSubButton } from "@/components/ui/sidebar";
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "@/components/ui/collapsible";
import { tools, type Tool } from "@/components/tool";
export const AppSidebar = () => {
// 递归构建完整路径
const buildFullPath = (pathSegments: string[]): string => {
return `/tool/${pathSegments.join("/")}`;
};
// 递归渲染子菜单内容
const renderSubMenuContent = (child: Tool, currentPaths: string[]): ReactNode => {
if (child.children) {
// 子菜单内的可折叠项
return (
{child.icon}
{child.name}
{child.children.map((subChild) => (
{renderSubMenuContent(subChild, [...currentPaths, child.path])}
))}
);
}
// 叶子节点
return (
{child.icon}
{child.name}
);
};
// 递归渲染菜单项
const renderMenuItem = (tool: Tool, parentPaths: string[] = []): ReactNode => {
const currentPaths = [...parentPaths, tool.path];
if (tool.children) {
// 有子菜单的项目
return (
{tool.icon}
{tool.name}
{tool.children.map((child) => (
{renderSubMenuContent(child, currentPaths)}
))}
);
}
// 没有子菜单的项目
return (
{tool.icon}
{tool.name}
);
};
return (
Lite Kit
Tools
{tools.map((tool) => renderMenuItem(tool))}
);
};