import{r as o,aQ as p,db as v,gz as b,gA as $,ds as m,bu as x}from"./index-C4inJ1rU.js";function y(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 D(e=y){return o.useCallback((t,n)=>{if(typeof e=="string"){let u=e;return(t==null?void 0:t[u])===(n==null?void 0:n[u])}return e(t,n)},[e])}var w=(e=>(e[e.Left=0]="Left",e[e.Right=2]="Right",e))(w||{});function M(e){let t=o.useRef(null),n=p(l=>{t.current=l.pointerType,!v(l.currentTarget)&&l.pointerType==="mouse"&&l.button===w.Left&&(l.preventDefault(),e(l))}),u=p(l=>{t.current!=="mouse"&&(v(l.currentTarget)||e(l))});return{onPointerDown:n,onClick:u}}var R=(e=>(e[e.Ignore=0]="Ignore",e[e.Select=1]="Select",e[e.Close=2]="Close",e))(R||{});const E={Ignore:{kind:0},Select:e=>({kind:1,target:e}),Close:{kind:2}},I=200,h=5;function N(e,{trigger:t,action:n,close:u,select:l}){let r=o.useRef(null),i=o.useRef(null),c=o.useRef(null);b(e&&t!==null,"pointerdown",s=>{$(s==null?void 0:s.target)&&t!=null&&t.contains(s.target)&&(i.current=s.x,c.current=s.y,r.current=s.timeStamp)}),b(e&&t!==null,"pointerup",s=>{var a,d;let f=r.current;if(f===null||(r.current=null,!m(s.target))||Math.abs(s.x-((a=i.current)!=null?a:s.x))<h&&Math.abs(s.y-((d=c.current)!=null?d:s.y))<h)return;let g=n(s);switch(g.kind){case 0:return;case 1:{s.timeStamp-f>I&&(l(g.target),u());break}case 2:{u();break}}},{capture:!0})}function k(e){return[e.screenX,e.screenY]}function j(){let e=o.useRef([-1,-1]);return{wasMoved(t){let n=k(t);return e.current[0]===n[0]&&e.current[1]===n[1]?!1:(e.current=n,!0)},update(t){e.current=k(t)}}}function L(e){throw new Error("Unexpected object: "+e)}var S=(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))(S||{});function z(e,t){let n=t.resolveItems();if(n.length<=0)return null;let u=t.resolveActiveIndex(),l=u??-1;switch(e.focus){case 0:{for(let r=0;r<n.length;++r)if(!t.resolveDisabled(n[r],r,n))return r;return u}case 1:{l===-1&&(l=n.length);for(let r=l-1;r>=0;--r)if(!t.resolveDisabled(n[r],r,n))return r;return u}case 2:{for(let r=l+1;r<n.length;++r)if(!t.resolveDisabled(n[r],r,n))return r;return u}case 3:{for(let r=n.length-1;r>=0;--r)if(!t.resolveDisabled(n[r],r,n))return r;return u}case 4:{for(let r=0;r<n.length;++r)if(t.resolveId(n[r],r,n)===e.id)return r;return u}case 5:return null;default:L(e)}}const P={Idle:{kind:"Idle"},Tracked:e=>({kind:"Tracked",position:e}),Moved:{kind:"Moved"}};function T(e){let t=e.getBoundingClientRect();return`${t.x},${t.y}`}function A(e,t,n){let u=x();if(t.kind==="Tracked"){let l=function(){r!==T(e)&&(u.dispose(),n())},{position:r}=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{N as L,E as S,P as a,T as b,S as c,D as d,z as f,w as g,A as p,M as s,j as u};
