import * as React from "react" import { ChevronRight } from "lucide-react" import Link from "next/link" import { SearchForm } from "@/components/search-form" import { VersionSwitcher } from "@/components/version-switcher" import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible" import { Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarRail, } from "@/components/ui/sidebar" import { useLayoutStore } from '@/stores/useLayoutStore'; // Define the interface for menu data interface MenuItem { title: string url: string isActive?: boolean } interface NavMainItem { title: string url: string icon?: string items: MenuItem[] } interface SidebarData { navMain: NavMainItem[] versions?: string[] } // Default data - used when no external data is provided const defaultData: SidebarData = { versions: ["1.0.0", "2.0.0"], navMain: [ { title: "Getting Started", url: "#", items: [ { title: "Installation", url: "#", }, { title: "Project Structure", url: "#", }, ], }, { title: "Building Your Application", url: "#", items: [ { title: "Routing", url: "#", }, { title: "Data Fetching", url: "#", isActive: true, }, { title: "Rendering", url: "#", }, { title: "Caching", url: "#", }, { title: "Styling", url: "#", }, ], }, { title: "API Reference", url: "#", items: [ { title: "Components", url: "#", }, { title: "File Conventions", url: "#", }, ], }, ], } export interface AppSidebarProps extends React.ComponentProps { data?: SidebarData } export function AppSidebar({ data, ...props }: AppSidebarProps) { // Use external data if provided, otherwise use default data const sidebarData = data || defaultData const { navigatorHeight } = useLayoutStore(); return ( {/* We create a collapsible SidebarGroup for each parent. */} {sidebarData.navMain.map((item) => (
{item.icon && {item.icon}} {item.title}
{item.items.map((subItem) => ( {subItem.url.startsWith('#') ? ( {subItem.title} ) : ( {subItem.title} )} ))}
))}
) }