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