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