"use client" import { useEffect, useState } from "react" import { ListIcon } from "lucide-react" import type { UpdateHeading } from "@/lib/updates" export function ChapterNav({ headings, }: { headings: UpdateHeading[] }) { const [activeId, setActiveId] = useState(headings[0]?.id ?? "") const [mobileOpen, setMobileOpen] = useState(false) useEffect(() => { const observers: IntersectionObserver[] = [] headings.forEach((heading) => { const element = document.getElementById(heading.id) if (!element) return const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { setActiveId(heading.id) } }) }, { rootMargin: "-20% 0px -70% 0px", }, ) observer.observe(element) observers.push(observer) }) return () => { observers.forEach((observer) => observer.disconnect()) } }, [headings]) if (headings.length === 0) return null return ( <> {/* Mobile toggle button */} {/* Mobile dropdown */} {mobileOpen && (
setMobileOpen(false)} /> )} ) }