'use client'
import type { ICommonItem, ICommonSection } from '~/components/reference/Reference.types'
import RevVersionDropdown from '~/components/RefVersionDropdown'
import { menuState, useMenuActiveRefId } from '~/hooks/useMenuState'
import { BASE_PATH } from '~/lib/constants'
import { ChevronUp } from 'lucide-react'
import Image from 'next/legacy/image'
import { Accordion } from 'radix-ui'
import { Fragment, memo } from 'react'
import { cn } from 'ui'
import MenuIconPicker from './MenuIconPicker'
import * as NavItems from './NavigationMenu.constants'
import { deepFilterSections } from './NavigationMenu.utils'
const HeaderLink = memo(function HeaderLink(props: any) {
return (
{props.title ?? props.id}
)
})
interface FunctionLinkProps {
title: string
name?: string
id: string
icon?: string
basePath: string
slug: string
isParent?: boolean
isSubItem?: boolean
onClick?: () => void
}
const FunctionLink = memo(function FunctionLink({
title,
id,
icon,
basePath,
slug,
isParent = false,
isSubItem = false,
onClick = () => {},
}: FunctionLinkProps) {
const activeAccordionItem = useMenuActiveRefId()
const url = `${BASE_PATH}${basePath}/${slug}`
const active = activeAccordionItem === id
return (
{
e.preventDefault()
menuState.setMenuActiveRefId(id)
history.pushState({}, '', url)
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
document.getElementById(slug)?.scrollIntoView({
behavior: reduceMotion ? 'auto' : 'smooth',
})
onClick()
}}
className={cn(
'cursor-pointer transition text-sm hover:text-foreground gap-3 relative',
isParent ? 'flex justify-between' : 'leading-3',
active ? 'text-brand' : 'text-foreground-lighter'
)}
>
{icon && }
{title}
{active && !isSubItem && (
)}
{isParent && (
)}
)
})
export interface RenderLinkProps {
section: ICommonSection
basePath: string
}
const RenderLink = memo(function RenderLink({ section, basePath }: RenderLinkProps) {
const activeAccordionItem = useMenuActiveRefId()
if (!('items' in section)) {
return (
menuState.setMenuMobileOpen(false)}
/>
)
}
let active =
section.id === activeAccordionItem ||
section.items.some((item) => item.id === activeAccordionItem)
return (
{section.items.map((item) => {
return (
menuState.setMenuMobileOpen(false)}
/>
)
})}
)
})
const SideMenuTitle = ({ title }: { title: string }) => {
return (
{title}
)
}
const Divider = () => {
return
}
interface NavigationMenuRefListItemsProps {
id: string
basePath: string
commonSections: ICommonItem[]
spec?: any
}
const NavigationMenuRefListItems = ({
id,
basePath,
commonSections,
spec,
}: NavigationMenuRefListItemsProps) => {
const menu = NavItems[id]
const specFunctionIds = spec?.functions.map(({ id }) => id)
const filteredSections = spec
? deepFilterSections(commonSections, specFunctionIds)
: commonSections
return (
{filteredSections.map((section) => {
return (
{section.type === 'category' ? (
<>
{section.items.map((item) => (
))}
>
) : (
)}
)
})}
)
}
export default memo(NavigationMenuRefListItems)