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