"use client";
import { useCallback, useEffect, useRef } from "react";
import { prefersReducedMotion } from "./motion-preference.js";
/**
 * Scrolls a line-faithful code view to `reveal.line` and reports which line to
 * highlight.
 *
 * The mechanics are centralized here (rather than duplicated into each line
 * renderer) and mirror the established `data-attribute` scroll pattern used by
 * the workflow waterfall: the consumer renders each row with `data-line="N"`
 * and this hook, on every `reveal.nonce` change, finds the target row within
 * `containerRef` and scrolls it into view. Smooth scroll yields to
 * `prefers-reduced-motion` (a JS animation the CSS rule does not cover), and
 * the scroll is an optional call so it is a no-op under jsdom, which has no
 * `scrollIntoView`.
 *
 * Placement matters: mount this inside the line renderer, which exists only
 * after the file content has loaded — never above the async content gate — so
 * the `[data-line]` rows are present when the effect runs and a fresh open does
 * not race the load. A missing or out-of-range line is a silent no-op.
 */
export function useRevealLine(reveal) {
    const containerRef = useRef(null);
    useEffect(() => {
        if (!reveal)
            return;
        const container = containerRef.current;
        if (!container)
            return;
        const row = container.querySelector(`[data-line="${reveal.line}"]`);
        // Optional call: jsdom (tests) implements no `scrollIntoView`.
        row?.scrollIntoView?.({
            block: "center",
            behavior: prefersReducedMotion() ? "auto" : "smooth",
        });
        // Intentionally keyed only on the nonce: a repeat navigation to the same
        // line (new nonce) must re-scroll, and `reveal.line` changes always ship a
        // new nonce, so it is covered transitively.
    }, [reveal?.nonce]);
    const isRevealed = useCallback((line) => reveal?.line === line, [reveal?.line]);
    return { containerRef, isRevealed };
}
//# sourceMappingURL=useRevealLine.js.map