import Link from 'next/link' import Image from 'next/image' import { useRouter } from 'next/router' import { IconChevronRight, IconArrowLeft } from '~/../../packages/ui' import { REFERENCES } from './Navigation.constants' import { NavMenuGroup, NavMenuSection } from './Navigation.types' import * as Accordion from '@radix-ui/react-accordion' const SideBar = ({ menuItems = [] }: { menuItems: any }) => { const { asPath } = useRouter() const pathSegments = asPath.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 === asPath) return item }) if (foundSubItem) return section } else { if (section.url === asPath) return section } }) if (foundItem) return group }) const currentSubSection: NavMenuSection = currentSection !== undefined ? currentSection.items.find((section) => { if (section.items.length === 0) { return undefined } else { return section.items.find((item) => { if (item.url === asPath) 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