"use client"; import { useEffect, useState } from "react"; import { cn, formatDate2 } from "@/lib/utils"; import { History, PanelLeftOpen, PanelLeftClose } from "lucide-react"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Button } from "@/components/ui/button"; interface VersionTocProps { versions: Array<{ version: string; date: string; }>; } export function VersionToc({ versions }: VersionTocProps) { const [activeId, setActiveId] = useState(null); const [collapsed, setCollapsed] = useState(false); useEffect(() => { const hash = window.location.hash.slice(1); if (hash) { setActiveId(hash); } const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { const id = entry.target.id; setActiveId(id); window.history.pushState(null, "", `#${id}`); } }); }, { threshold: 0.2, rootMargin: "-20% 0px -60% 0px", } ); versions.forEach(({ version }) => { const element = document.getElementById(`v${version}`); if (element) observer.observe(element); }); return () => observer.disconnect(); }, [versions]); return ( ); }