import T, { useState as g, useRef as d, useCallback as u, useEffect as y } from "react";
import { useSSRSafeId as P } from "../../ssr/dist/module.es.js";
import { clsx as I } from "../../../clsx/dist/clsx.m.es.js";
const $ = typeof window < "u" ? T.useLayoutEffect : () => {
};
let p = /* @__PURE__ */ new Map();
function E(e) {
  let [t, a] = g(e), r = d(null), n = P(t), l = u((o) => {
    r.current = o;
  }, []);
  return p.set(n, l), $(() => {
    let o = n;
    return () => {
      p.delete(o);
    };
  }, [
    n
  ]), y(() => {
    let o = r.current;
    o && (r.current = null, a(o));
  }), n;
}
function C(e, t) {
  if (e === t)
    return e;
  let a = p.get(e);
  if (a)
    return a(t), t;
  let r = p.get(t);
  return r ? (r(e), e) : t;
}
function X(e = []) {
  let t = E(), [a, r] = _(t), n = u(() => {
    r(function* () {
      yield t, yield document.getElementById(t) ? t : void 0;
    });
  }, [
    t,
    r
  ]);
  return $(n, [
    t,
    n,
    ...e
  ]), a;
}
function A(...e) {
  return (...t) => {
    for (let a of e)
      typeof a == "function" && a(...t);
  };
}
function Y(...e) {
  let t = {
    ...e[0]
  };
  for (let a = 1; a < e.length; a++) {
    let r = e[a];
    for (let n in r) {
      let l = t[n], o = r[n];
      typeof l == "function" && typeof o == "function" && n[0] === "o" && n[1] === "n" && n.charCodeAt(2) >= 65 && n.charCodeAt(2) <= 90 ? t[n] = A(l, o) : (n === "className" || n === "UNSAFE_className") && typeof l == "string" && typeof o == "string" ? t[n] = I(l, o) : n === "id" && l && o ? t.id = C(l, o) : t[n] = o !== void 0 ? o : l;
    }
  }
  return t;
}
const M = /* @__PURE__ */ new Set([
  "id"
]), N = /* @__PURE__ */ new Set([
  "aria-label",
  "aria-labelledby",
  "aria-describedby",
  "aria-details"
]), k = /^(data-.*)$/;
function V(e, t = {}) {
  let { labelable: a, propNames: r } = t, n = {};
  for (const l in e)
    Object.prototype.hasOwnProperty.call(e, l) && (M.has(l) || a && N.has(l) || (r == null ? void 0 : r.has(l)) || k.test(l)) && (n[l] = e[l]);
  return n;
}
function B(e) {
  if (D())
    e.focus({
      preventScroll: !0
    });
  else {
    let t = G(e);
    e.focus(), R(t);
  }
}
let b = null;
function D() {
  if (b == null) {
    b = !1;
    try {
      var e = document.createElement("div");
      e.focus({
        get preventScroll() {
          return b = !0, !0;
        }
      });
    } catch {
    }
  }
  return b;
}
function G(e) {
  for (var t = e.parentNode, a = [], r = document.scrollingElement || document.documentElement; t instanceof HTMLElement && t !== r; )
    (t.offsetHeight < t.scrollHeight || t.offsetWidth < t.scrollWidth) && a.push({
      element: t,
      scrollTop: t.scrollTop,
      scrollLeft: t.scrollLeft
    }), t = t.parentNode;
  return r instanceof HTMLElement && a.push({
    element: r,
    scrollTop: r.scrollTop,
    scrollLeft: r.scrollLeft
  }), a;
}
function R(e) {
  for (let { element: t, scrollTop: a, scrollLeft: r } of e)
    t.scrollTop = a, t.scrollLeft = r;
}
let s = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set();
function L() {
  if (typeof window > "u")
    return;
  let e = (a) => {
    let r = s.get(a.target);
    r || (r = /* @__PURE__ */ new Set(), s.set(a.target, r), a.target.addEventListener("transitioncancel", t)), r.add(a.propertyName);
  }, t = (a) => {
    let r = s.get(a.target);
    if (!!r && (r.delete(a.propertyName), r.size === 0 && (a.target.removeEventListener("transitioncancel", t), s.delete(a.target)), s.size === 0)) {
      for (let n of v)
        n();
      v.clear();
    }
  };
  document.body.addEventListener("transitionrun", e), document.body.addEventListener("transitionend", t);
}
typeof document < "u" && (document.readyState !== "loading" ? L() : document.addEventListener("DOMContentLoaded", L));
function J(e) {
  requestAnimationFrame(() => {
    s.size === 0 ? e() : v.add(e);
  });
}
function Q() {
  let e = d(/* @__PURE__ */ new Map()), t = u((n, l, o, f) => {
    let i = f != null && f.once ? (...c) => {
      e.current.delete(o), o(...c);
    } : o;
    e.current.set(o, {
      type: l,
      eventTarget: n,
      fn: i,
      options: f
    }), n.addEventListener(l, o, f);
  }, []), a = u((n, l, o, f) => {
    var i;
    let c = ((i = e.current.get(o)) === null || i === void 0 ? void 0 : i.fn) || o;
    n.removeEventListener(l, c, f), e.current.delete(o);
  }, []), r = u(() => {
    e.current.forEach((n, l) => {
      a(n.eventTarget, n.type, l, n.options);
    });
  }, [
    a
  ]);
  return y(() => r, [
    r
  ]), {
    addGlobalListener: t,
    removeGlobalListener: a,
    removeAllGlobalListeners: r
  };
}
function Z(e, t) {
  let { id: a, "aria-label": r, "aria-labelledby": n } = e;
  return a = E(a), n && r ? n = [
    .../* @__PURE__ */ new Set([
      ...n.trim().split(/\s+/),
      a
    ])
  ].join(" ") : n && (n = n.trim().split(/\s+/).join(" ")), !r && !n && t && (r = t), {
    id: a,
    "aria-label": r,
    "aria-labelledby": n
  };
}
function ee(e, t) {
  $(() => {
    if (e && e.ref && t)
      return e.ref.current = t.current, () => {
        e.ref.current = null;
      };
  }, [
    e,
    t
  ]);
}
let O = 0;
const m = /* @__PURE__ */ new Map();
function te(e) {
  let [t, a] = g(void 0);
  return $(() => {
    if (!e)
      return;
    let r = m.get(e);
    if (r)
      a(r.element.id);
    else {
      let n = `react-aria-description-${O++}`;
      a(n);
      let l = document.createElement("div");
      l.id = n, l.style.display = "none", l.textContent = e, document.body.appendChild(l), r = {
        refCount: 0,
        element: l
      }, m.set(e, r);
    }
    return r.refCount++, () => {
      --r.refCount === 0 && (r.element.remove(), m.delete(e));
    };
  }, [
    e
  ]), {
    "aria-describedby": e ? t : void 0
  };
}
function h(e) {
  var t;
  return typeof window > "u" || window.navigator == null ? !1 : ((t = window.navigator.userAgentData) === null || t === void 0 ? void 0 : t.brands.some(
    (a) => e.test(a.brand)
  )) || e.test(window.navigator.userAgent);
}
function x(e) {
  var t;
  return typeof window < "u" && window.navigator != null ? e.test(((t = window.navigator.userAgentData) === null || t === void 0 ? void 0 : t.platform) || window.navigator.platform) : !1;
}
function S() {
  return x(/^Mac/i);
}
function W() {
  return x(/^iPhone/i);
}
function H() {
  return x(/^iPad/i) || S() && navigator.maxTouchPoints > 1;
}
function z() {
  return W() || H();
}
function re() {
  return S() || z();
}
function ne() {
  return h(/AppleWebKit/i) && !j();
}
function j() {
  return h(/Chrome/i);
}
function U() {
  return h(/Android/i);
}
function ae(e, t, a, r) {
  let n = d(a);
  n.current = a;
  let l = a == null;
  y(() => {
    if (l)
      return;
    let o = e.current, f = (i) => n.current.call(this, i);
    return o.addEventListener(t, f, r), () => {
      o.removeEventListener(t, f, r);
    };
  }, [
    e,
    t,
    r,
    l
  ]);
}
function _(e) {
  let [t, a] = g(e), r = d(t), n = d(null);
  r.current = t;
  let l = d(null);
  l.current = () => {
    let f = n.current.next();
    if (f.done) {
      n.current = null;
      return;
    }
    t === f.value ? l.current() : a(f.value);
  }, $(() => {
    n.current && l.current();
  });
  let o = u((f) => {
    n.current = f(r.current), l.current();
  }, [
    n,
    l
  ]);
  return [
    t,
    o
  ];
}
function le(e, t) {
  let a = w(e, t, "left"), r = w(e, t, "top"), n = t.offsetWidth, l = t.offsetHeight, o = e.scrollLeft, f = e.scrollTop, i = o + e.offsetWidth, c = f + e.offsetHeight;
  a <= o ? o = a : a + n > i && (o += a + n - i), r <= f ? f = r : r + l > c && (f += r + l - c), e.scrollLeft = o, e.scrollTop = f;
}
function w(e, t, a) {
  const r = a === "left" ? "offsetLeft" : "offsetTop";
  let n = 0;
  for (; t.offsetParent && (n += t[r], t.offsetParent !== e); ) {
    if (t.offsetParent.contains(e)) {
      n -= e[r];
      break;
    }
    t = t.offsetParent;
  }
  return n;
}
function oe(e) {
  return e.mozInputSource === 0 && e.isTrusted ? !0 : U() && e.pointerType ? e.type === "click" && e.buttons === 1 : e.detail === 0 && !e.pointerType;
}
function fe(e) {
  return e.width === 0 && e.height === 0 || e.width === 1 && e.height === 1 && e.pressure === 0 && e.detail === 0 && e.pointerType === "mouse";
}
export {
  A as chain,
  V as filterDOMProps,
  B as focusWithoutScrolling,
  U as isAndroid,
  re as isAppleDevice,
  j as isChrome,
  z as isIOS,
  H as isIPad,
  W as isIPhone,
  S as isMac,
  oe as isVirtualClick,
  fe as isVirtualPointerEvent,
  ne as isWebKit,
  C as mergeIds,
  Y as mergeProps,
  J as runAfterTransition,
  le as scrollIntoView,
  te as useDescription,
  ae as useEvent,
  Q as useGlobalListeners,
  E as useId,
  Z as useLabels,
  $ as useLayoutEffect,
  X as useSlotId,
  ee as useSyncRef,
  _ as useValueEffect
};
//# sourceMappingURL=module.es.js.map
