import{__awaiter as r,__generator as e}from'./../../ext-esm/tslib/tslib.es6.js';import{jsx as n}from"react/jsx-runtime";import{useState as t,useCallback as o,useMemo as c,useEffect as i}from"react";import{FilesLoaderV2 as a}from"../FilesLoaderV2/FilesLoaderV2.js";var u=function(u){var s=u.onStatusChange,l=u.file,f=u.processFile,d=u.onDelete,m=u.formatProgress,v=t({total:0,current:0}),p=v[0],g=v[1],h=t(),b=h[0],j=h[1],x=t(!1),C=x[0],F=x[1],w=t(),y=w[0],D=w[1],E=o((function(r,e){g({total:r,current:e})}),[]),L=c((function(){if(y)return function(){y(),F(!0),s({success:!1,cancelled:!0,file:l})}}),[y]),P=o((function(){var n=!1;return function(t){return r(void 0,void 0,void 0,(function(){var r,o,c,i;return e(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),r=function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];n||E.apply(void 0,r)},[4,f(t,r,(function(r){D((function(){return function(){n=!0,r()}}))}))];case 1:return o=e.sent(),n?[2]:(g((function(r){var e=r.total;return{total:e,current:e}})),s({success:!0,cancelled:!1,data:o,file:t}),[3,3]);case 2:return c=e.sent(),n?[2]:(i=c instanceof Error?c:new Error(String(c)),j(i),s({success:!1,cancelled:!1,error:i,file:t}),[3,3]);case 3:return[2]}}))}))}}),[f,s]),S=o((function(){j(void 0),F(!1),s({file:l,success:!1,data:void 0,error:void 0,cancelled:!1}),P()(l)}),[l,P,s]),V=o((function(){d(l)}),[d,l]);i((function(){P()(l)}),[l,P]);var R=b?null==b?void 0:b.message:C?"Cancelled":null;return n(a,{name:l.name,total:p.total,current:p.current,errorText:R,onCancel:L,onReload:S,onDelete:V,formatProgress:m})};export{u as Processor};
