import { $ as P, a as L } from "./utils-V7nfNEif.es.js";
import { $ as M } from "./useGlobalListeners-BOOfV5Wh.es.js";
import { useState as G, useRef as N, useEffect as b, useMemo as x } from "react";
let d = !1, u = 0;
function g() {
  d = !0, setTimeout(() => {
    d = !1;
  }, 50);
}
function H(f) {
  f.pointerType === "touch" && g();
}
function D() {
  if (!(typeof document > "u"))
    return u === 0 && (typeof PointerEvent < "u" ? document.addEventListener("pointerup", H) : process.env.NODE_ENV === "test" && document.addEventListener("touchend", g)), u++, () => {
      u--, !(u > 0) && (typeof PointerEvent < "u" ? document.removeEventListener("pointerup", H) : process.env.NODE_ENV === "test" && document.removeEventListener("touchend", g));
    };
}
function V(f) {
  let { onHoverStart: l, onHoverChange: a, onHoverEnd: v, isDisabled: r } = f, [h, E] = G(!1), t = N({
    isHovered: !1,
    ignoreEmulatedMouseEvents: !1,
    pointerType: "",
    target: null
  }).current;
  b(D, []);
  let { addGlobalListener: c, removeAllGlobalListeners: $ } = M(), { hoverProps: T, triggerHoverEnd: y } = x(() => {
    let m = (e, n) => {
      if (t.pointerType = n, r || n === "touch" || t.isHovered || !e.currentTarget.contains(e.target)) return;
      t.isHovered = !0;
      let i = e.currentTarget;
      t.target = i, c(P(e.target), "pointerover", (p) => {
        t.isHovered && t.target && !L(t.target, p.target) && s(p, p.pointerType);
      }, {
        capture: !0
      }), l && l({
        type: "hoverstart",
        target: i,
        pointerType: n
      }), a && a(!0), E(!0);
    }, s = (e, n) => {
      let i = t.target;
      t.pointerType = "", t.target = null, !(n === "touch" || !t.isHovered || !i) && (t.isHovered = !1, $(), v && v({
        type: "hoverend",
        target: i,
        pointerType: n
      }), a && a(!1), E(!1));
    }, o = {};
    return typeof PointerEvent < "u" ? (o.onPointerEnter = (e) => {
      d && e.pointerType === "mouse" || m(e, e.pointerType);
    }, o.onPointerLeave = (e) => {
      !r && e.currentTarget.contains(e.target) && s(e, e.pointerType);
    }) : process.env.NODE_ENV === "test" && (o.onTouchStart = () => {
      t.ignoreEmulatedMouseEvents = !0;
    }, o.onMouseEnter = (e) => {
      !t.ignoreEmulatedMouseEvents && !d && m(e, "mouse"), t.ignoreEmulatedMouseEvents = !1;
    }, o.onMouseLeave = (e) => {
      !r && e.currentTarget.contains(e.target) && s(e, "mouse");
    }), {
      hoverProps: o,
      triggerHoverEnd: s
    };
  }, [
    l,
    a,
    v,
    r,
    t,
    c,
    $
  ]);
  return b(() => {
    r && y({
      currentTarget: t.target
    }, t.pointerType);
  }, [
    r
  ]), {
    hoverProps: T,
    isHovered: h
  };
}
export {
  V as $
};
//# sourceMappingURL=useHover-BiPYlZr_.es.js.map
