import e from"@babel/runtime/helpers/toConsumableArray";import r from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import{jsxs as n,jsx as o}from"react/jsx-runtime";import{useState as i,useEffect as c,useCallback as s}from"react";import l from"classnames";import{FilesDropzone as u}from"../FilesDropzone/FilesDropzone.js";import{FilesLoader as a}from"../FilesLoader/FilesLoader.js";import{Processor as f}from"./Processor.js";import m from"./FilesProcessor.scss.js";function p(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}var b=function(r){var p=r.multiple,b=r.accept,v=r.className,g=r.processFile,O=r.value,j=void 0===O?[]:O,h=r.onDone,y=r.onDelete,P=r.maxFiles,D=r.maxSize,F=r.formatProgress,w=r.onProcessingFailure,x=r.onStartProcessing,S=r.testId,z=i([]),N=t(z,2),A=N[0],C=N[1];c((function(){A.length>0&&A.every((function(e){return"success"in e}))&&A.some((function(e){return e.success}))&&(C((function(e){return e.filter((function(e){return!e.success}))})),h(A.filter((function(e){var r=e.success,t=e.data;return!!r&&!!t})).map((function(e){return e.data}))))}),[A,h]);var E=s((function(e){C((function(r){return r.filter((function(r){return r.file!==e}))}))}),[]),L=s((function(e){e.success||null==w||w(e.file,e.cancelled,e.error),C((function(r){return r.map((function(r){return r.file===e.file?d(d({},r),{},{data:e.data,success:e.success,cancelled:e.cancelled}):r}))}))}),[w]),k=s((function(r){null==x||x(r);var t=r.map((function(e){return{file:e}}));C((function(r){return[].concat(e(r),e(t))}))}),[x]);return n("div",{className:l(m.root,v),"data-testid":S,children:[(p||0===A.length&&0===(null==j?void 0:j.length))&&o(u,{multiple:p,onDrop:k,accept:b,maxFiles:P,maxSize:D}),(A.length>0||(null==j?void 0:j.length)>0)&&n("div",{className:m.files,children:[A.map((function(e){return o(f,{processFile:g,onStatusChange:L,file:e.file,onDelete:E,formatProgress:F},"".concat(e.file.size,"|").concat(e.file.name))})),null==j?void 0:j.map((function(e,r){return o(a,{name:e.name,onDelete:y?function(){return y(e)}:void 0,complete:!0},r)}))]})]})};export{b as FilesProcessor};
//# sourceMappingURL=FilesProcessor.js.map
