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