import {useEffect, useRef, useState} from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import clsx from 'clsx'
import { AnimatePresence, motion, useIsPresent } from 'framer-motion'
import { Button } from '@/components/Button'
import { useIsInsideMobileNavigation } from '@/components/MobileNavigation'
import { useSectionStore } from '@/components/SectionProvider'
import { Tag } from '@/components/Tag'
import { remToPx } from '@/lib/remToPx'
function useInitialValue(value, condition = true) {
let initialValue = useRef(value).current
return condition ? initialValue : value
}
export function TopLevelNavItem({ href, children }) {
return (
{children}
)
}
export function NavLink({ href, tag, active, isAnchorLink = false, children }) {
return (
{children}
{tag && (
{tag}
)}
)
}
export function VisibleSectionHighlight({ group, pathname }) {
let height = remToPx(2)
let offset = remToPx(0)
let activePageIndex = group.links.findIndex((link) => link.href === pathname)
let top = offset + activePageIndex * height
return (
)
}
export function ActivePageMarker({ group, pathname }) {
let itemHeight = remToPx(2)
let offset = remToPx(0.25)
let activePageIndex = group.links.findIndex((link) => link.href === pathname)
let top = offset + activePageIndex * itemHeight
return (
)
}
function NavigationGroup({ group, className, tableOfContents }) {
// If this is the mobile navigation then we always render the initial
// state, so that the state does not change during the close animation.
// The state will still update when we re-open (re-render) the navigation.
// let isInsideMobileNavigation = useIsInsideMobileNavigation()
let router = useRouter()
// let [router, sections] = useInitialValue(
// [useRouter(), useSectionStore((s) => s.sections)],
// isInsideMobileNavigation
// )
let isActiveGroup =
group.links.findIndex((link) => link.href === router.pathname) !== -1
return (