import { b as T } from "./mergeProps-B-cqsBhL.es.js";
import { useState as y } from "react";
function W(e, o) {
  if (!e) return !1;
  let l = window.getComputedStyle(e), t = /(auto|scroll)/.test(l.overflow + l.overflowX + l.overflowY);
  return t && o && (t = e.scrollHeight !== e.clientHeight || e.scrollWidth !== e.clientWidth), t;
}
function I(e, o) {
  const l = [];
  for (; e && e !== document.documentElement; )
    W(e, o) && l.push(e), e = e.parentElement;
  return l;
}
let S = 0;
const u = /* @__PURE__ */ new Map();
function R(e) {
  let [o, l] = y();
  return T(() => {
    if (!e) return;
    let t = u.get(e);
    if (t)
      l(t.element.id);
    else {
      let d = `react-aria-description-${S++}`;
      l(d);
      let f = document.createElement("div");
      f.id = d, f.style.display = "none", f.textContent = e, document.body.appendChild(f), t = {
        refCount: 0,
        element: f
      }, u.set(e, t);
    }
    return t.refCount++, () => {
      t && --t.refCount === 0 && (t.element.remove(), u.delete(e));
    };
  }, [
    e
  ]), {
    "aria-describedby": e ? o : void 0
  };
}
function k(e, o) {
  let l = m(e, o, "left"), t = m(e, o, "top"), d = o.offsetWidth, f = o.offsetHeight, r = e.scrollLeft, i = e.scrollTop, { borderTopWidth: c, borderLeftWidth: n, scrollPaddingTop: a, scrollPaddingRight: s, scrollPaddingBottom: x, scrollPaddingLeft: C } = getComputedStyle(e), L = r + parseInt(n, 10), b = i + parseInt(c, 10), p = L + e.clientWidth, $ = b + e.clientHeight, v = parseInt(a, 10) || 0, h = parseInt(x, 10) || 0, P = parseInt(s, 10) || 0, g = parseInt(C, 10) || 0;
  l <= r + g ? r = l - parseInt(n, 10) - g : l + d > p - P && (r += l + d - p + P), t <= b + v ? i = t - parseInt(c, 10) - v : t + f > $ - h && (i += t + f - $ + h), e.scrollLeft = r, e.scrollTop = i;
}
function m(e, o, l) {
  const t = l === "left" ? "offsetLeft" : "offsetTop";
  let d = 0;
  for (; o.offsetParent && (d += o[t], o.offsetParent !== e); ) {
    if (o.offsetParent.contains(e)) {
      d -= e[t];
      break;
    }
    o = o.offsetParent;
  }
  return d;
}
function H(e, o) {
  if (e && document.contains(e)) {
    let r = document.scrollingElement || document.documentElement, i = window.getComputedStyle(r).overflow === "hidden";
    if (i) {
      let c = I(e);
      i || c.push(r);
      for (let n of c) k(n, e);
    } else {
      var l;
      let { left: c, top: n } = e.getBoundingClientRect();
      e == null || (l = e.scrollIntoView) === null || l === void 0 || l.call(e, {
        block: "nearest"
      });
      let { left: a, top: s } = e.getBoundingClientRect();
      if (Math.abs(c - a) > 1 || Math.abs(n - s) > 1) {
        var t, d, f;
        o == null || (d = o.containingElement) === null || d === void 0 || (t = d.scrollIntoView) === null || t === void 0 || t.call(d, {
          block: "center",
          inline: "center"
        }), (f = e.scrollIntoView) === null || f === void 0 || f.call(e, {
          block: "nearest"
        });
      }
    }
  }
}
export {
  W as $,
  R as a,
  k as b,
  H as c
};
//# sourceMappingURL=scrollIntoView-Btu7DgIo.es.js.map
