import { $ as b } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import { b as E } from "./mergeProps-B-cqsBhL.es.js";
import { useRef as h, useCallback as w } from "react";
const y = (e) => {
  var t;
  return (t = e?.ownerDocument) !== null && t !== void 0 ? t : document;
}, $ = (e) => e && "window" in e && e.window === e ? e : y(e).defaultView || window;
function x(e) {
  return e !== null && typeof e == "object" && "nodeType" in e && typeof e.nodeType == "number";
}
function L(e) {
  return x(e) && e.nodeType === Node.DOCUMENT_FRAGMENT_NODE && "host" in e;
}
let T = !1, g = !1;
function j() {
  return T;
}
function u() {
  return g;
}
function C(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 : L(n) ? n = n.host : n = n.parentNode;
  }
  return !1;
}
const I = (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 F = typeof Element < "u" && "checkVisibility" in Element.prototype;
function M(e) {
  const t = $(e);
  if (!(e instanceof t.HTMLElement) && !(e instanceof t.SVGElement)) return !1;
  let { display: n, visibility: a } = e.style, s = n !== "none" && a !== "hidden" && a !== "collapse";
  if (s) {
    const { getComputedStyle: o } = e.ownerDocument.defaultView;
    let { display: i, visibility: d } = o(e);
    s = i !== "none" && d !== "hidden" && d !== "collapse";
  }
  return s;
}
function S(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 F ? e.checkVisibility({
    visibilityProperty: !0
  }) && !e.closest("[data-react-aria-prevent-focus]") : e.nodeName !== "#comment" && M(e) && S(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"
], A = /* @__PURE__ */ p.join(":not([hidden]),") + ",[tabindex]:not([disabled]):not([hidden])", N = /* @__PURE__ */ p.join(':not([hidden]):not([tabindex="-1"]),');
function O(e) {
  return e.matches(A) && f(e) && !v(e);
}
function _(e) {
  return e.matches(N) && 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 P(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 B(e) {
  let t = h({
    isFocused: !1,
    observer: null
  });
  return E(() => {
    const n = t.current;
    return () => {
      n.observer && (n.observer.disconnect(), n.observer = null);
    };
  }, []), w((n) => {
    if (n.target instanceof HTMLButtonElement || n.target instanceof HTMLInputElement || n.target instanceof HTMLTextAreaElement || n.target instanceof HTMLSelectElement) {
      t.current.isFocused = !0;
      let a = n.target, s = (o) => {
        if (t.current.isFocused = !1, a.disabled) {
          let i = P(o);
          e?.(i);
        }
        t.current.observer && (t.current.observer.disconnect(), t.current.observer = null);
      };
      a.addEventListener("focusout", s, {
        once: !0
      }), t.current.observer = new MutationObserver(() => {
        if (t.current.isFocused && a.disabled) {
          var o;
          (o = t.current.observer) === null || o === void 0 || o.disconnect();
          let i = a === document.activeElement ? null : document.activeElement;
          a.dispatchEvent(new FocusEvent("blur", {
            relatedTarget: i
          })), a.dispatchEvent(new FocusEvent("focusout", {
            bubbles: !0,
            relatedTarget: i
          }));
        }
      }), t.current.observer.observe(a, {
        attributes: !0,
        attributeFilter: [
          "disabled"
        ]
      });
    }
  }, [
    e
  ]);
}
let l = !1;
function U(e) {
  for (; e && !O(e); ) e = e.parentElement;
  let t = $(e), n = t.document.activeElement;
  if (!n || n === e) return;
  l = !0;
  let a = !1, s = (r) => {
    (r.target === n || a) && r.stopImmediatePropagation();
  }, o = (r) => {
    (r.target === n || a) && (r.stopImmediatePropagation(), !e && !a && (a = !0, b(n), c()));
  }, i = (r) => {
    (r.target === e || a) && r.stopImmediatePropagation();
  }, d = (r) => {
    (r.target === e || a) && (r.stopImmediatePropagation(), a || (a = !0, b(n), c()));
  };
  t.addEventListener("blur", s, !0), t.addEventListener("focusout", o, !0), t.addEventListener("focusin", d, !0), t.addEventListener("focus", i, !0);
  let c = () => {
    cancelAnimationFrame(m), t.removeEventListener("blur", s, !0), t.removeEventListener("focusout", o, !0), t.removeEventListener("focusin", d, !0), t.removeEventListener("focus", i, !0), l = !1, a = !1;
  }, m = requestAnimationFrame(c);
  return c;
}
export {
  y as $,
  C as a,
  B as b,
  I as c,
  H as d,
  k as e,
  P as f,
  u as g,
  _ as h,
  O as i,
  $ as j,
  l as k,
  U as l,
  j as m
};
//# sourceMappingURL=utils-V7nfNEif.es.js.map
