import { c as W, a as m, d as x, e as v, b as T, f as B, g as E } from "./utils-oAGBWzI5.es.js";
import { useRef as G, useCallback as $ } from "react";
import { $ as L } from "./useGlobalListeners-BOOfV5Wh.es.js";
function A(b) {
  let { isDisabled: h, onBlurWithin: i, onFocusWithin: o, onFocusWithinChange: t } = b, r = G({
    isFocusWithin: !1
  }), { addGlobalListener: c, removeAllGlobalListeners: s } = L(), n = $((e) => {
    e.currentTarget.contains(e.target) && r.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget) && (r.current.isFocusWithin = !1, s(), i && i(e), t && t(!1));
  }, [
    i,
    t,
    r,
    s
  ]), u = W(n), p = $((e) => {
    if (!e.currentTarget.contains(e.target)) return;
    const a = m(e.target), g = x(a);
    if (!r.current.isFocusWithin && g === v(e.nativeEvent)) {
      o && o(e), t && t(!0), r.current.isFocusWithin = !0, u(e);
      let f = e.currentTarget;
      c(a, "focus", (l) => {
        if (r.current.isFocusWithin && !T(f, l.target)) {
          let d = new a.defaultView.FocusEvent("blur", {
            relatedTarget: l.target
          });
          B(d, f);
          let F = E(d);
          n(F);
        }
      }, {
        capture: !0
      });
    }
  }, [
    o,
    t,
    u,
    c,
    n
  ]);
  return h ? {
    focusWithinProps: {
      // These cannot be null, that would conflict in mergeProps
      onFocus: void 0,
      onBlur: void 0
    }
  } : {
    focusWithinProps: {
      onFocus: p,
      onBlur: n
    }
  };
}
export {
  A as $
};
//# sourceMappingURL=useFocusWithin-EFOG-Jn1.es.js.map
