"use client"; import { useState, useEffect } from "react"; import { History } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Separator } from "@/components/ui/separator"; interface FloatingVersionTocProps { versions: { version: string; date: string }[]; } export function FloatingVersionToc({ versions }: FloatingVersionTocProps) { const [open, setOpen] = useState(false); const [activeVersion, setActiveVersion] = useState(versions[0]?.version || ""); useEffect(() => { const handleIntersection = (entries: IntersectionObserverEntry[]) => { entries.forEach((entry) => { if (entry.isIntersecting) { setActiveVersion(entry.target.id.replace("version-", "")); } }); }; const observer = new IntersectionObserver(handleIntersection, { root: null, rootMargin: "-64px 0px -50% 0px", threshold: 0.25, }); versions.forEach(({ version }) => { const section = document.getElementById(`version-${version}`); if (section) observer.observe(section); }); return () => observer.disconnect(); }, [versions]); const handleScrollToVersion = (version: string) => { const element = document.getElementById(`version-${version}`); if (element) { setTimeout(() => { element.scrollIntoView({ behavior: "smooth", block: "start" }); }, 100); setActiveVersion(version); setOpen(false); } }; return (