import{__assign as e,__spreadArray as n}from'./../../ext-esm/tslib/tslib.es6.js';import{jsxs as r,jsx as t}from"react/jsx-runtime";import{useState as o,useEffect as i,useCallback as s}from"react";import{FilesDropzone as l}from"../FilesDropzone/FilesDropzone.js";import"../../utils/index.js";import{FilesLoaderV2 as c}from"../FilesLoaderV2/FilesLoaderV2.js";import{useStyles as u}from"./styles.js";import a from"classnames";import{Processor as f}from"./Processor.js";var m=function(m){var p=m.multiple,d=m.accept,v=m.className,g=m.processFile,F=m.value,h=void 0===F?[]:F,j=m.onDone,x=m.onDelete,D=m.maxFiles,z=m.maxSize,P=m.formatProgress,S=m.onProcessingFailure,N=m.onStartProcessing,b=u(),y=o([]),L=y[0],V=y[1];i((function(){L.length>0&&L.every((function(e){return"success"in e}))&&L.some((function(e){return e.success}))&&(V((function(e){return e.filter((function(e){return!e.success}))})),j(L.filter((function(e){return e.success})).map((function(e){return e.data}))))}),[L]);var C=s((function(e){V((function(n){return n.filter((function(n){return n.file!==e}))}))}),[]),_=s((function(n){n.success||null==S||S(n.file,n.cancelled,n.error),V((function(r){return r.map((function(r){return r.file===n.file?e(e({},r),{data:n.data,success:n.success}):r}))}))}),[]),k=s((function(e){null==N||N(e);var r=e.map((function(e){return{file:e}}));V((function(e){return n(n([],e,!0),r,!0)}))}),[]);return r("div",e({className:a(b.root,v)},{children:[(p||0===L.length&&0===(null==h?void 0:h.length))&&t(l,{multiple:p,onDrop:k,accept:d,maxFiles:D,maxSize:z}),(L.length>0||(null==h?void 0:h.length)>0)&&r("div",e({className:b.files},{children:[L.map((function(e){return t(f,{processFile:g,onStatusChange:_,file:e.file,onDelete:C,formatProgress:P},"".concat(e.file.size,"|").concat(e.file.name))})),null==h?void 0:h.map((function(e){return t(c,{name:e.name,onDelete:x?function(){return x(e)}:void 0,total:0,current:0})}))]}))]}))};export{m as FilesProcessor};
