import{r as o,aq as v,cx as b,eS as h,eT as w,cO as x,b2 as c,b5 as R}from"./index-CeMilrX4.js";function S(e,t){return e!==null&&t!==null&&typeof e=="object"&&typeof t=="object"&&"id"in e&&"id"in t?e.id===t.id:e===t}function N(e=S){return o.useCallback((t,r)=>{if(typeof e=="string"){let u=e;return(t==null?void 0:t[u])===(r==null?void 0:r[u])}return e(t,r)},[e])}var $=(e=>(e[e.Left=0]="Left",e[e.Right=2]="Right",e))($||{});function j(e){let t=o.useRef(null),r=v(l=>{t.current=l.pointerType,!b(l.currentTarget)&&l.pointerType==="mouse"&&l.button===$.Left&&(l.preventDefault(),e(l))}),u=v(l=>{t.current!=="mouse"&&(b(l.currentTarget)||e(l))});return{onPointerDown:r,onClick:u}}var y=(e=>(e[e.Ignore=0]="Ignore",e[e.Select=1]="Select",e[e.Close=2]="Close",e))(y||{});const z={Ignore:{kind:0},Select:e=>({kind:1,target:e}),Close:{kind:2}},I=200,k=5;function F(e,{trigger:t,action:r,close:u,select:l}){let n=o.useRef(null),i=o.useRef(null),a=o.useRef(null);h(e&&t!==null,"pointerdown",s=>{w(s==null?void 0:s.target)&&t!=null&&t.contains(s.target)&&(i.current=s.x,a.current=s.y,n.current=s.timeStamp)}),h(e&&t!==null,"pointerup",s=>{var d,f;let g=n.current;if(g===null||(n.current=null,!x(s.target))||Math.abs(s.x-((d=i.current)!=null?d:s.x))<k&&Math.abs(s.y-((f=a.current)!=null?f:s.y))<k)return;let p=r(s);switch(p.kind){case 0:return;case 1:{s.timeStamp-g>I&&(l(p.target),u());break}case 2:{u();break}}},{capture:!0})}function m(e){return[e.screenX,e.screenY]}function P(){let e=o.useRef([-1,-1]);return{wasMoved(t){let r=m(t);return e.current[0]===r[0]&&e.current[1]===r[1]?!1:(e.current=r,!0)},update(t){e.current=m(t)}}}function L({children:e,freeze:t},r){let u=T(t,e);return o.isValidElement(u)?o.cloneElement(u,{ref:r}):c.createElement(c.Fragment,null,u)}const O=c.forwardRef(L);function T(e,t){let[r,u]=o.useState(t);return!e&&r!==t&&u(t),e?r:t}function E(e){throw new Error("Unexpected object: "+e)}var C=(e=>(e[e.First=0]="First",e[e.Previous=1]="Previous",e[e.Next=2]="Next",e[e.Last=3]="Last",e[e.Specific=4]="Specific",e[e.Nothing=5]="Nothing",e))(C||{});function q(e,t){let r=t.resolveItems();if(r.length<=0)return null;let u=t.resolveActiveIndex(),l=u??-1;switch(e.focus){case 0:{for(let n=0;n<r.length;++n)if(!t.resolveDisabled(r[n],n,r))return n;return u}case 1:{l===-1&&(l=r.length);for(let n=l-1;n>=0;--n)if(!t.resolveDisabled(r[n],n,r))return n;return u}case 2:{for(let n=l+1;n<r.length;++n)if(!t.resolveDisabled(r[n],n,r))return n;return u}case 3:{for(let n=r.length-1;n>=0;--n)if(!t.resolveDisabled(r[n],n,r))return n;return u}case 4:{for(let n=0;n<r.length;++n)if(t.resolveId(r[n],n,r)===e.id)return n;return u}case 5:return null;default:E(e)}}const A={Idle:{kind:"Idle"},Tracked:e=>({kind:"Tracked",position:e}),Moved:{kind:"Moved"}};function D(e){let t=e.getBoundingClientRect();return`${t.x},${t.y}`}function B(e,t,r){let u=R();if(t.kind==="Tracked"){let l=function(){n!==D(e)&&(u.dispose(),r())},{position:n}=t,i=new ResizeObserver(l);i.observe(e),u.add(()=>i.disconnect()),u.addEventListener(window,"scroll",l,{passive:!0}),u.addEventListener(window,"resize",l)}return()=>u.dispose()}export{F as L,z as S,A as a,D as b,C as c,O as d,P as e,q as f,$ as g,N as h,B as p,j as s,T as u};
