import { REFERENCES } from '~/content/navigation.references' import { ArrowLeft, ChevronRight } from 'lucide-react' import Image from 'next/legacy/image' import Link from 'next/link' import { usePathname } from 'next/navigation' import { Accordion } from 'radix-ui' import { NavMenuGroup, NavMenuSection } from './Navigation.types' const SideBar = ({ menuItems = [] }: { menuItems: any }) => { const pathname = usePathname() const pathSegments = pathname.split('/') const isInReferencePages = pathSegments.includes('reference') && pathSegments.length >= 3 const referenceMeta = pathSegments.length >= 3 ? REFERENCES[pathSegments[2]] : undefined const currentSection: NavMenuGroup = menuItems.find((group) => { const foundItem = group.items.find((section) => { if (section.items.length > 0) { const foundSubItem = section.items.find((item) => { if (item.url === pathname) return item }) if (foundSubItem) return section } else { if (section.url === pathname) return section } }) if (foundItem) return group }) const currentSubSection: NavMenuSection | undefined = currentSection !== undefined ? currentSection.items.find((section) => { if (section.items.length === 0) { return undefined } else { return section.items.find((item) => { if (item.url === pathname) return item }) } }) : undefined return (
{isInReferencePages && ( <>
All Reference Docs
{referenceMeta !== undefined && (
{referenceMeta.name}

{referenceMeta.name}

)} )} {menuItems.length === 1 ? (
{menuItems[0].items.map((item) => (
{item.name}
))}
) : ( {menuItems.map((group: NavMenuGroup) => ( {group.label} {group.items.map((section: NavMenuSection) => { if (section.items.length === 0) { return (
{section.name}
) } else { return ( {section.name} {section.items.map((item: NavMenuSection) => (
{item.name}
))}
) } })}
))}
)}
) } export default SideBar