import{r as n,Y as C,Z as T,_ as g,$ as h,j as x}from"./index-B1H8BCL7.js";function p(s){return s.substring(2).toLowerCase()}function w(s,o){return o.documentElement.clientWidth<s.clientX||o.documentElement.clientHeight<s.clientY}function P(s){const{children:o,disableReactTree:R=!1,mouseEvent:u="onClick",onClickAway:L,touchEvent:i="onTouchEnd"}=s,l=n.useRef(!1),c=n.useRef(null),f=n.useRef(!1),d=n.useRef(!1);n.useEffect(()=>(setTimeout(()=>{f.current=!0},0),()=>{f.current=!1}),[]);const k=C(T(o),c),a=g(e=>{const t=d.current;d.current=!1;const r=h(c.current);if(!f.current||!c.current||"clientX"in e&&w(e,r))return;if(l.current){l.current=!1;return}let E;e.composedPath?E=e.composedPath().indexOf(c.current)>-1:E=!r.documentElement.contains(e.target)||c.current.contains(e.target),!E&&(R||!t)&&L(e)}),v=e=>t=>{d.current=!0;const r=o.props[e];r&&r(t)},m={ref:k};return i!==!1&&(m[i]=v(i)),n.useEffect(()=>{if(i!==!1){const e=p(i),t=h(c.current),r=()=>{l.current=!0};return t.addEventListener(e,a),t.addEventListener("touchmove",r),()=>{t.removeEventListener(e,a),t.removeEventListener("touchmove",r)}}},[a,i]),u!==!1&&(m[u]=v(u)),n.useEffect(()=>{if(u!==!1){const e=p(u),t=h(c.current);return t.addEventListener(e,a),()=>{t.removeEventListener(e,a)}}},[a,u]),x.jsx(n.Fragment,{children:n.cloneElement(o,m)})}export{P as C};
