import { useSyntheticBlurEvent as l } from "./utils.js";
import { useCallback as u } from "react";
import { getActiveElement as a, getEventTarget as p } 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/DOMFunctions.js";
import { getOwnerDocument as m } 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/domHelpers.js";
function x(d) {
  let { isDisabled: r, onFocus: n, onBlur: o, onFocusChange: t } = d;
  const c = u((e) => {
    if (e.target === e.currentTarget)
      return o && o(e), t && t(!1), !0;
  }, [
    o,
    t
  ]), f = l(c), i = u((e) => {
    const s = m(e.target), $ = s ? a(s) : a();
    e.target === e.currentTarget && $ === p(e.nativeEvent) && (n && n(e), t && t(!0), f(e));
  }, [
    t,
    n,
    f
  ]);
  return {
    focusProps: {
      onFocus: !r && (n || t || o) ? i : void 0,
      onBlur: !r && (o || t) ? c : void 0
    }
  };
}
export {
  x as useFocus
};
