"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./utils.mjs.js"),t=require("react");require("../../utils/dist/useId.mjs.js");var s=require("../../utils/dist/DOMFunctions.mjs.js"),r=require("../../utils/dist/domHelpers.mjs.js");require("../../utils/dist/platform.mjs.js"),require("../../utils/dist/runAfterTransition.mjs.js");var i=require("../../utils/dist/useGlobalListeners.mjs.js");require("../../utils/dist/useLayoutEffect.mjs.js"),require("../../utils/dist/useEffectEvent.mjs.js"),require("react-dom"),exports.useFocusWithin=function(u){let{isDisabled:n,onBlurWithin:o,onFocusWithin:c,onFocusWithinChange:a}=u,l=t.useRef({isFocusWithin:!1}),{addGlobalListener:d,removeAllGlobalListeners:j}=i.useGlobalListeners(),g=t.useCallback((e=>{e.currentTarget.contains(e.target)&&l.current.isFocusWithin&&!e.currentTarget.contains(e.relatedTarget)&&(l.current.isFocusWithin=!1,j(),o&&o(e),a&&a(!1))}),[o,a,l,j]),f=e.useSyntheticBlurEvent(g),v=t.useCallback((t=>{if(!t.currentTarget.contains(t.target))return;const i=r.getOwnerDocument(t.target),u=s.getActiveElement(i);if(!l.current.isFocusWithin&&u===s.getEventTarget(t.nativeEvent)){c&&c(t),a&&a(!0),l.current.isFocusWithin=!0,f(t);let r=t.currentTarget;d(i,"focus",(t=>{if(l.current.isFocusWithin&&!s.nodeContains(r,t.target)){let s=new i.defaultView.FocusEvent("blur",{relatedTarget:t.target});e.setEventTarget(s,r);let u=e.createSyntheticEvent(s);g(u)}}),{capture:!0})}}),[c,a,f,d,g]);return n?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:v,onBlur:g}}};
//# sourceMappingURL=useFocusWithin.mjs.js.map
