import{G as j,H as w,b as x,R as O,r as u}from"./main-D6SjkSWq.js";import{u as a,r as h}from"./file-upload-provider-C966C2x1.js";import{o as C}from"./open-upload-window-DxsWEG58.js";function k(t){return x.post("file-entries/delete",t).then(n=>n.data)}function I(){return j({mutationFn:t=>k(t),onError:t=>w(t)})}const y=t=>Symbol.iterator in t,m=t=>"entries"in t,F=(t,n)=>{const o=t instanceof Map?t:new Map(t.entries()),s=n instanceof Map?n:new Map(n.entries());if(o.size!==s.size)return!1;for(const[i,e]of o)if(!s.has(i)||!Object.is(e,s.get(i)))return!1;return!0},M=(t,n)=>{const o=t[Symbol.iterator](),s=n[Symbol.iterator]();let i=o.next(),e=s.next();for(;!i.done&&!e.done;){if(!Object.is(i.value,e.value))return!1;i=o.next(),e=s.next()}return!!i.done&&!!e.done};function R(t,n){return Object.is(t,n)?!0:typeof t!="object"||t===null||typeof n!="object"||n===null||Object.getPrototypeOf(t)!==Object.getPrototypeOf(n)?!1:y(t)&&y(n)?m(t)&&m(n)?F(t,n):M(t,n):F({entries:()=>Object.entries(t)},{entries:()=>Object.entries(n)})}function z(t){const n=O.useRef(void 0);return o=>{const s=t(o);return R(n.current,s)?n.current:n.current=s}}function G(){const t=I(),n=u.useRef(null),o=a(r=>r.uploadSingle),s=a(r=>r.abortUpload),i=a(r=>r.updateFileUpload),e=a(z(r=>n.current?r.fileUploads.get(n.current):null)),f=u.useCallback((r,c)=>{n.current=o(r,c)},[o]),g=u.useCallback(async r=>{const c=h(r),l=await C({types:c==null?void 0:c.allowedFileTypes});return f(l[0],r),l[0]},[f]),E=u.useCallback(({onSuccess:r,entryPath:c})=>{var p,d,b;const l=()=>{e&&i(e.file.id,{...e,entry:void 0}),r()};if(!c&&!((p=e==null?void 0:e.entry)!=null&&p.id)){l();return}t.mutate({paths:c?[c]:void 0,entryIds:(d=e==null?void 0:e.entry)!=null&&d.id?[(b=e==null?void 0:e.entry)==null?void 0:b.id]:void 0,deleteForever:!0},{onSuccess:l})},[t,e,i]),S=u.useCallback(()=>{e&&s(e.file.id)},[e,s]);return{uploadFile:f,selectAndUploadFile:g,percentage:(e==null?void 0:e.percentage)||0,uploadStatus:e==null?void 0:e.status,entry:e==null?void 0:e.entry,deleteEntry:E,isDeletingEntry:t.isPending,activeUpload:e,abortUpload:S}}export{G as u};
