"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("../../utils/dist/useId.mjs.js");var e=require("../../utils/dist/DOMFunctions.mjs.js"),t=require("../../utils/dist/domHelpers.mjs.js");require("../../utils/dist/platform.mjs.js");var r=require("react");require("../../utils/dist/runAfterTransition.mjs.js");var n=require("../../utils/dist/useGlobalListeners.mjs.js");require("../../utils/dist/useLayoutEffect.mjs.js"),require("../../utils/dist/useEffectEvent.mjs.js"),require("react-dom");let o=!1,s=0;function i(){o=!0,setTimeout((()=>{o=!1}),50)}function u(e){"touch"===e.pointerType&&i()}function a(){if("undefined"!=typeof document)return 0===s&&("undefined"!=typeof PointerEvent?document.addEventListener("pointerup",u):"test"===process.env.NODE_ENV&&document.addEventListener("touchend",i)),s++,()=>{s--,s>0||("undefined"!=typeof PointerEvent?document.removeEventListener("pointerup",u):"test"===process.env.NODE_ENV&&document.removeEventListener("touchend",i))}}exports.useHover=function(s){let{onHoverStart:i,onHoverChange:u,onHoverEnd:d,isDisabled:p}=s,[v,c]=r.useState(!1),l=r.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;r.useEffect(a,[]);let{addGlobalListener:E,removeAllGlobalListeners:g}=n.useGlobalListeners(),{hoverProps:m,triggerHoverEnd:f}=r.useMemo((()=>{let r=(r,o)=>{if(l.pointerType=o,p||"touch"===o||l.isHovered||!r.currentTarget.contains(r.target))return;l.isHovered=!0;let s=r.currentTarget;l.target=s,E(t.getOwnerDocument(r.target),"pointerover",(t=>{l.isHovered&&l.target&&!e.nodeContains(l.target,t.target)&&n(t,t.pointerType)}),{capture:!0}),i&&i({type:"hoverstart",target:s,pointerType:o}),u&&u(!0),c(!0)},n=(e,t)=>{let r=l.target;l.pointerType="",l.target=null,"touch"!==t&&l.isHovered&&r&&(l.isHovered=!1,g(),d&&d({type:"hoverend",target:r,pointerType:t}),u&&u(!1),c(!1))},s={};return"undefined"!=typeof PointerEvent?(s.onPointerEnter=e=>{o&&"mouse"===e.pointerType||r(e,e.pointerType)},s.onPointerLeave=e=>{!p&&e.currentTarget.contains(e.target)&&n(e,e.pointerType)}):"test"===process.env.NODE_ENV&&(s.onTouchStart=()=>{l.ignoreEmulatedMouseEvents=!0},s.onMouseEnter=e=>{l.ignoreEmulatedMouseEvents||o||r(e,"mouse"),l.ignoreEmulatedMouseEvents=!1},s.onMouseLeave=e=>{!p&&e.currentTarget.contains(e.target)&&n(e,"mouse")}),{hoverProps:s,triggerHoverEnd:n}}),[i,u,d,p,l,E,g]);return r.useEffect((()=>{p&&f({currentTarget:l.target},l.pointerType)}),[p]),{hoverProps:m,isHovered:v}};
//# sourceMappingURL=useHover.mjs.js.map
