"use client"; import { useEffect, useState } from "react"; import { track } from "@/lib/analytics"; /* The right-hand rail of a manual page: the headings with the one on screen marked, whether the * page helped, and print and copy-link. The answer to "was this useful" goes to the product's own * usage statistics as a counted event naming the page and nothing about the reader. */ export default function ManualToc({ headings, page }: { headings: { id: string; n: string; text: string }[]; page: string }) { const [cur, setCur] = useState(headings[0]?.id ?? ""); const [voted, setVoted] = useState<"" | "yes" | "no">(""); const [copied, setCopied] = useState(false); useEffect(() => { if (typeof IntersectionObserver === "undefined") return; const seen = new Map(); const io = new IntersectionObserver((entries) => { for (const e of entries) seen.set((e.target as HTMLElement).id, e.isIntersecting); const first = headings.find((h) => seen.get(h.id)); if (first) setCur(first.id); }, { rootMargin: "-80px 0px -60% 0px" }); for (const h of headings) { const el = document.getElementById(h.id); if (el) io.observe(el); } return () => io.disconnect(); }, [headings]); return ( ); }