"use client"; import { useEffect, useState } from "react"; import { useTranslations } from "next-intl"; import type { HelpHeading } from "../types/help-article.types"; import { MicroLabel } from "../../../components/typography"; export function HelpTOC({ headings }: { headings: readonly HelpHeading[] }) { const t = useTranslations(); const [active, setActive] = useState(null); useEffect(() => { const observer = new IntersectionObserver( (entries) => { for (const e of entries) { if (e.isIntersecting) setActive(e.target.id); } }, { rootMargin: "0px 0px -70% 0px", threshold: 0 }, ); headings.forEach((h) => { const el = document.getElementById(h.slug); if (el) observer.observe(el); }); return () => observer.disconnect(); }, [headings]); if (headings.length === 0) return null; return ( ); }