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