import { useLayoutEffect as o } from "../../../../../@react-aria_utils@3.33.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@react-aria/utils/dist/useLayoutEffect.js";
import { useRef as u, useCallback as d } from "react";
function l(t) {
  let e = t;
  return e.nativeEvent = t, e.isDefaultPrevented = () => e.defaultPrevented, e.isPropagationStopped = () => e.cancelBubble, e.persist = () => {
  }, e;
}
function v(t, e) {
  Object.defineProperty(t, "target", {
    value: e
  }), Object.defineProperty(t, "currentTarget", {
    value: e
  });
}
function f(t) {
  let e = u({
    isFocused: !1,
    observer: null
  });
  return o(() => {
    const r = e.current;
    return () => {
      r.observer && (r.observer.disconnect(), r.observer = null);
    };
  }, []), d((r) => {
    if (r.target instanceof HTMLButtonElement || r.target instanceof HTMLInputElement || r.target instanceof HTMLTextAreaElement || r.target instanceof HTMLSelectElement) {
      e.current.isFocused = !0;
      let n = r.target, s = (c) => {
        if (e.current.isFocused = !1, n.disabled) {
          let a = l(c);
          t == null || t(a);
        }
        e.current.observer && (e.current.observer.disconnect(), e.current.observer = null);
      };
      n.addEventListener("focusout", s, {
        once: !0
      }), e.current.observer = new MutationObserver(() => {
        if (e.current.isFocused && n.disabled) {
          var c;
          (c = e.current.observer) === null || c === void 0 || c.disconnect();
          let a = n === document.activeElement ? null : document.activeElement;
          n.dispatchEvent(new FocusEvent("blur", {
            relatedTarget: a
          })), n.dispatchEvent(new FocusEvent("focusout", {
            bubbles: !0,
            relatedTarget: a
          }));
        }
      }), e.current.observer.observe(n, {
        attributes: !0,
        attributeFilter: [
          "disabled"
        ]
      });
    }
  }, [
    t
  ]);
}
let p = !1;
export {
  l as createSyntheticEvent,
  p as ignoreFocusEvent,
  v as setEventTarget,
  f as useSyntheticBlurEvent
};
