"use client"; import { useEffect, useRef } from "react"; /** Scroll to a DOM id and briefly highlight after data loads. */ export function useLiveFocusScroll( focusId: string | null | undefined, elementIdPrefix: string, ready: boolean, ) { const doneRef = useRef(null); useEffect(() => { if (!focusId || !ready) return; const token = `${elementIdPrefix}${focusId}`; if (doneRef.current === token) return; const el = document.getElementById(`${elementIdPrefix}${focusId}`); if (!el) return; doneRef.current = token; const t = window.setTimeout(() => { el.scrollIntoView({ behavior: "smooth", block: "center" }); el.classList.add("yt-live-focus-highlight"); window.setTimeout(() => el.classList.remove("yt-live-focus-highlight"), 4500); }, 280); return () => clearTimeout(t); }, [focusId, ready, elementIdPrefix]); }