"use strict";const P=require("./jsx-runtime-nZSsnGb7.cjs"),x=require("@synnaxlabs/x"),t=require("react"),f=require("zod"),j=require("./Text-XHBXXDRS.cjs"),T=f.z.object({key:f.z.string().or(f.z.number()),type:f.z.string(),elementID:f.z.string().optional(),data:x.record.unknownZ.optional()}),h=f.z.object({source:T,items:f.z.array(T)}),O={key:"",type:""},g={source:O,items:[]},_="file",q={key:"file",type:_},M=new Set(["all","copyLink"]),H=(e,r)=>M.has(e.dataTransfer.effectAllowed)&&r.items.length===0,[Z,y]=j.create({defaultValue:null,displayName:"Haul.Context"}),b={...g,onSuccessfulDrop:()=>{}},C=t.memo(({children:e,useState:r=t.useState,onDropOutside:s})=>{const c=y(),[i,n]=r(g),u=t.useRef(b),l=t.useRef(new Set),d=t.useCallback((o,a,k)=>{u.current={source:o,items:a,onSuccessfulDrop:k},n({source:o,items:a})},[n,s]),p=t.useCallback(({target:o,dropped:a})=>{const k=u.current.items;u.current.onSuccessfulDrop?.({target:o,dropped:a,hauled:k}),u.current=b,n(g)},[n]),D=t.useCallback(o=>{let a=null;l.current.forEach(k=>{a==null&&(a=k(u.current,o))}),a!=null&&p(a),u.current=b,n(g)},[n]),m=t.useCallback(o=>(l.current.add(o),()=>l.current.delete(o)),[]),E=t.useMemo(()=>c??{state:i,start:d,end:D,drop:p,bind:m},[i,d,D,p,c]);return P.jsxRuntimeExports.jsx(Z,{value:E,children:e})});C.displayName="HaulProvider";const F=()=>{const e=t.useRef(g),r=y();return r==null||(e.current=r.state),e},I=()=>{const e=y();return e==null?g:e.state},z=({type:e,key:r})=>{const s=r??t.useId(),c=t.useMemo(()=>({key:s,type:e}),[s,e]),i=y();if(i==null)return{startDrag:()=>{},onDragEnd:()=>{}};const{start:n,end:u}=i;return{startDrag:t.useCallback((l,d)=>n(c,l,d),[n,c]),onDragEnd:l=>u(x.xy.construct({x:l.screenX,y:l.screenY}))}},R=({type:e,key:r,canDrop:s,onDrop:c,onDragOver:i})=>{const n=F(),u=y();if(u==null)return{onDragOver:()=>{},onDrop:()=>{}};const{drop:l}=u,d=r??t.useId(),p=t.useMemo(()=>({key:d,type:e}),[d,e]),D=t.useRef({x:-1,y:-1}),m=t.useCallback(o=>{o.preventDefault();const a=x.xy.construct({x:o.screenX,y:o.screenY});x.xy.equals(a,D.current)||(D.current=a,s(n.current)&&i?.({event:o,...n.current}))},[n,s]),E=t.useCallback(o=>{s(n.current)&&(o.preventDefault(),l({target:p,dropped:c({...n.current,event:o})}))},[n,c,s,l,p]);return{onDragOver:m,onDrop:E}},A=({type:e,key:r,...s})=>{const c=r??t.useId(),i=t.useMemo(()=>({key:c,type:e}),[c,e]),n=z(i),u=R({...s,...i});return{...n,...u}},v=e=>({items:r})=>r.some(s=>s.type===e),S=(e,r)=>r.filter(s=>s.type===e),L=(e,r,s)=>t.useCallback(c=>r({...c,items:S(e,c.items)}),s),w=Object.freeze(Object.defineProperty({__proto__:null,FILE:q,FILE_TYPE:_,Provider:C,ZERO_DRAGGING_STATE:g,ZERO_ITEM:O,canDropOfType:v,draggingStateZ:h,filterByType:S,isFileDrag:H,itemZ:T,useContext:y,useDrag:z,useDragAndDrop:A,useDraggingRef:F,useDraggingState:I,useDrop:R,useFilterByTypeCallback:L},Symbol.toStringTag,{value:"Module"}));exports.FILE_TYPE=_;exports.Haul=w;exports.Provider=C;exports.canDropOfType=v;exports.filterByType=S;exports.useDragAndDrop=A;exports.useDraggingState=I;exports.useDrop=R;exports.useFilterByTypeCallback=L;
