import*as e from"react";import*as n from"react-dom";import t from"../../../../prop-types/index.js";import r from"../utils/ownerDocument.js";import o from"../utils/useForkRef.js";import u from"../utils/useEventCallback.js";import c from"../../../utils/esm/elementAcceptingRef.js";import i from"../../../utils/esm/exactProp.js";function s(e){return e.substring(2).toLowerCase()}function f(t){var c=t.children,i=t.disableReactTree,f=void 0!==i&&i,m=t.mouseEvent,a=void 0===m?"onClick":m,l=t.onClickAway,d=t.touchEvent,p=void 0===d?"onTouchEnd":d,v=e.useRef(!1),E=e.useRef(null),h=e.useRef(!1),R=e.useRef(!1);e.useEffect((function(){return setTimeout((function(){h.current=!0}),0),function(){h.current=!1}}),[]);var T=e.useCallback((function(e){E.current=n.findDOMNode(e)}),[]),k=o(c.ref,T),C=u((function(e){var n=R.current;if(R.current=!1,h.current&&E.current&&!function(e){return document.documentElement.clientWidth<e.clientX||document.documentElement.clientHeight<e.clientY}(e))if(v.current)v.current=!1;else{var t;if(e.composedPath)t=e.composedPath().indexOf(E.current)>-1;else t=!r(E.current).documentElement.contains(e.target)||E.current.contains(e.target);t||!f&&n||l(e)}})),L=function(e){return function(n){R.current=!0;var t=c.props[e];t&&t(n)}},b={ref:k};return!1!==p&&(b[p]=L(p)),e.useEffect((function(){if(!1!==p){var e=s(p),n=r(E.current),t=function(){v.current=!0};return n.addEventListener(e,C),n.addEventListener("touchmove",t),function(){n.removeEventListener(e,C),n.removeEventListener("touchmove",t)}}}),[C,p]),!1!==a&&(b[a]=L(a)),e.useEffect((function(){if(!1!==a){var e=s(a),n=r(E.current);return n.addEventListener(e,C),function(){n.removeEventListener(e,C)}}}),[C,a]),e.createElement(e.Fragment,null,e.cloneElement(c,b))}"production"!==process.env.NODE_ENV&&(f.propTypes={children:c.isRequired,disableReactTree:t.bool,mouseEvent:t.oneOf(["onClick","onMouseDown","onMouseUp",!1]),onClickAway:t.func.isRequired,touchEvent:t.oneOf(["onTouchEnd","onTouchStart",!1])}),"production"!==process.env.NODE_ENV&&(f.propTypes=i(f.propTypes));export default f;
//# sourceMappingURL=ClickAwayListener.js.map
