import { $ as b } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import { d as E, c as h } from "./mergeProps-Dsl8k3Ig.es.js";
import { useRef as w, useCallback as y } from "react";
const x = (e) => {
  var t;
  return (t = e?.ownerDocument) !== null && t !== void 0 ? t : document;
}, $ = (e) => e && "window" in e && e.window === e ? e : x(e).defaultView || window;
function L(e) {
  return e !== null && typeof e == "object" && "nodeType" in e && typeof e.nodeType == "number";
}
function T(e) {
  return L(e) && e.nodeType === Node.DOCUMENT_FRAGMENT_NODE && "host" in e;
}
let g = !1, F = !1;
function C() {
  return g;
}
function u() {
  return F;
}
function I(e, t) {
  if (!u()) return t && e ? e.contains(t) : !1;
  if (!e || !t) return !1;
  let n = t;
  for (; n !== null; ) {
    if (n === e) return !0;
    n.tagName === "SLOT" && n.assignedSlot ? n = n.assignedSlot.parentNode : T(n) ? n = n.host : n = n.parentNode;
  }
  return !1;
}
const B = (e = document) => {
  var t;
  if (!u()) return e.activeElement;
  let n = e.activeElement;
  for (; n && "shadowRoot" in n && (!((t = n.shadowRoot) === null || t === void 0) && t.activeElement); ) n = n.shadowRoot.activeElement;
  return n;
};
function H(e) {
  return u() && e.target.shadowRoot && e.composedPath ? e.composedPath()[0] : e.target;
}
const M = typeof Element < "u" && "checkVisibility" in Element.prototype;
function S(e) {
  const t = $(e);
  if (!(e instanceof t.HTMLElement) && !(e instanceof t.SVGElement)) return !1;
  let { display: n, visibility: a } = e.style, r = n !== "none" && a !== "hidden" && a !== "collapse";
  if (r) {
    const { getComputedStyle: d } = e.ownerDocument.defaultView;
    let { display: i, visibility: s } = d(e);
    r = i !== "none" && s !== "hidden" && s !== "collapse";
  }
  return r;
}
function A(e, t) {
  return !e.hasAttribute("hidden") && // Ignore HiddenSelect when tree walking.
  !e.hasAttribute("data-react-aria-prevent-focus") && (e.nodeName === "DETAILS" && t && t.nodeName !== "SUMMARY" ? e.hasAttribute("open") : !0);
}
function f(e, t) {
  return M ? e.checkVisibility({
    visibilityProperty: !0
  }) && !e.closest("[data-react-aria-prevent-focus]") : e.nodeName !== "#comment" && S(e) && A(e, t) && (!e.parentElement || f(e.parentElement, e));
}
const p = [
  "input:not([disabled]):not([type=hidden])",
  "select:not([disabled])",
  "textarea:not([disabled])",
  "button:not([disabled])",
  "a[href]",
  "area[href]",
  "summary",
  "iframe",
  "object",
  "embed",
  "audio[controls]",
  "video[controls]",
  '[contenteditable]:not([contenteditable^="false"])',
  "permission"
], N = /* @__PURE__ */ p.join(":not([hidden]),") + ",[tabindex]:not([disabled]):not([hidden])", O = /* @__PURE__ */ p.join(':not([hidden]):not([tabindex="-1"]),');
function P(e) {
  return e.matches(N) && f(e) && !v(e);
}
function _(e) {
  return e.matches(O) && f(e) && !v(e);
}
function v(e) {
  let t = e;
  for (; t != null; ) {
    if (t instanceof t.ownerDocument.defaultView.HTMLElement && t.inert) return !0;
    t = t.parentElement;
  }
  return !1;
}
function R(e) {
  let t = e;
  return t.nativeEvent = e, t.isDefaultPrevented = () => t.defaultPrevented, t.isPropagationStopped = () => t.cancelBubble, t.persist = () => {
  }, t;
}
function k(e, t) {
  Object.defineProperty(e, "target", {
    value: t
  }), Object.defineProperty(e, "currentTarget", {
    value: t
  });
}
function U(e) {
  let t = w({
    isFocused: !1,
    observer: null
  });
  E(() => {
    const a = t.current;
    return () => {
      a.observer && (a.observer.disconnect(), a.observer = null);
    };
  }, []);
  let n = h((a) => {
    e?.(a);
  });
  return y((a) => {
    if (a.target instanceof HTMLButtonElement || a.target instanceof HTMLInputElement || a.target instanceof HTMLTextAreaElement || a.target instanceof HTMLSelectElement) {
      t.current.isFocused = !0;
      let r = a.target, d = (i) => {
        if (t.current.isFocused = !1, r.disabled) {
          let s = R(i);
          n(s);
        }
        t.current.observer && (t.current.observer.disconnect(), t.current.observer = null);
      };
      r.addEventListener("focusout", d, {
        once: !0
      }), t.current.observer = new MutationObserver(() => {
        if (t.current.isFocused && r.disabled) {
          var i;
          (i = t.current.observer) === null || i === void 0 || i.disconnect();
          let s = r === document.activeElement ? null : document.activeElement;
          r.dispatchEvent(new FocusEvent("blur", {
            relatedTarget: s
          })), r.dispatchEvent(new FocusEvent("focusout", {
            bubbles: !0,
            relatedTarget: s
          }));
        }
      }), t.current.observer.observe(r, {
        attributes: !0,
        attributeFilter: [
          "disabled"
        ]
      });
    }
  }, [
    n
  ]);
}
let l = !1;
function G(e) {
  for (; e && !P(e); ) e = e.parentElement;
  let t = $(e), n = t.document.activeElement;
  if (!n || n === e) return;
  l = !0;
  let a = !1, r = (o) => {
    (o.target === n || a) && o.stopImmediatePropagation();
  }, d = (o) => {
    (o.target === n || a) && (o.stopImmediatePropagation(), !e && !a && (a = !0, b(n), c()));
  }, i = (o) => {
    (o.target === e || a) && o.stopImmediatePropagation();
  }, s = (o) => {
    (o.target === e || a) && (o.stopImmediatePropagation(), a || (a = !0, b(n), c()));
  };
  t.addEventListener("blur", r, !0), t.addEventListener("focusout", d, !0), t.addEventListener("focusin", s, !0), t.addEventListener("focus", i, !0);
  let c = () => {
    cancelAnimationFrame(m), t.removeEventListener("blur", r, !0), t.removeEventListener("focusout", d, !0), t.removeEventListener("focusin", s, !0), t.removeEventListener("focus", i, !0), l = !1, a = !1;
  }, m = requestAnimationFrame(c);
  return c;
}
export {
  $,
  x as a,
  I as b,
  U as c,
  B as d,
  H as e,
  k as f,
  R as g,
  u as h,
  _ as i,
  P as j,
  l as k,
  G as l,
  C as m
};
//# sourceMappingURL=utils-oAGBWzI5.es.js.map
