import { jsx as B } from "react/jsx-runtime";
import { useRef as C, useState as N, useMemo as O, useEffect as K } from "react";
import { t as M } from "../global.module.js";
import { c as R, s as j, a as k } from "../tools/tools.js";
const w = function(S) {
  const {
    as: v = "div",
    children: h,
    className: l,
    dropOldClass: a,
    onActiveChange: s,
    rootMargin: i = "0px 0px -25%",
    sectionIds: o = [],
    smoothScroll: m,
    style: f,
    threshold: d = 0.5,
    variables: p,
    ...b
  } = S, u = C(null), [I, x] = N(null), E = O(() => {
    const r = R(!a && "", m && M.brlScrollSmooth, l), t = j((n, e) => ({ tKey: k(e) }), p, f);
    return {
      className: r,
      style: t
    };
  }, [l, a, m, f, p]);
  return K(() => {
    const r = u.current;
    if (!r)
      return;
    const t = new IntersectionObserver(
      (e) => {
        for (const y of e)
          if (y.isIntersecting) {
            const c = o.find((g) => y.target.id === g);
            if (c) {
              x(c), s == null || s(c);
              break;
            }
          }
      },
      {
        root: r,
        rootMargin: i,
        threshold: d
      }
    ), n = o.map((e) => document.getElementById(e)).filter(Boolean);
    return n.forEach((e) => e && t.observe(e)), () => {
      n.forEach((e) => e && t.unobserve(e)), t.disconnect();
    };
  }, [s, i, o, d]), /* @__PURE__ */ B(v, { ...b, ...E, ref: u, children: h(I) });
};
w.displayName = "BRL.Scrollspy";
export {
  w as S
};
//# sourceMappingURL=scrollspy.js.map
