Liferay.Loader.define("item-selector-taglib@5.2.21/item_selector_uploader/js/SingleFileUploader",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/form","@frontend-taglib-clay$clayui/layout","@frontend-taglib-clay$clayui/progress-bar","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$classnames","frontend-js-web","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","item-selector-taglib$react-dropzone","../../item_selector_preview/js/ItemSelectorPreview.es","./components/DragFilePlaceholder","./utils/getPreviewProps","./utils/getUploadErrorMessage","./utils/sendFile"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=a("@frontend-taglib-clay$clayui/button"),r=v(a("@frontend-taglib-clay$clayui/form")),n=v(a("@frontend-taglib-clay$clayui/layout")),o=v(a("@frontend-taglib-clay$clayui/progress-bar")),i=a("@liferay/frontend-js-react-web"),u=v(a("liferay!frontend-js-react-web$classnames")),d=a("frontend-js-web"),s=(v(a("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=b();if(t&&t.has(e))return t.get(e);var a={},l=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){var n=l?Object.getOwnPropertyDescriptor(e,r):null;n&&(n.get||n.set)?Object.defineProperty(a,r,n):a[r]=e[r]}a.default=e,t&&t.set(e,a);return a}(a("liferay!frontend-js-react-web$react"))),c=a("item-selector-taglib$react-dropzone"),f=v(a("../../item_selector_preview/js/ItemSelectorPreview.es")),p=v(a("./components/DragFilePlaceholder")),m=v(a("./utils/getPreviewProps")),y=v(a("./utils/getUploadErrorMessage")),g=v(a("./utils/sendFile"));function b(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return b=function(){return e},e}function v(e){return e&&e.__esModule?e:{default:e}}function E(){return(E=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e}).apply(this,arguments)}var w=function({closeCaption:e,editImageURL:t,itemSelectedEventName:a,maxFileSize:b=Liferay.PropsValues.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE,mimeTypeRestriction:v,uploadItemReturnType:w,uploadItemURL:j,validExtensions:P}){const[S,L]=(0,s.useState)(null),[_,F]=(0,s.useState)(!1),[$,C]=(0,s.useState)(""),[I,O]=(0,s.useState)(),[h,M]=(0,s.useState)(null),[R,z]=(0,s.useState)(null),[D,T]=(0,s.useState)(!1),x=(0,i.useIsMounted)(),N=Number(b),U=(0,s.useMemo)((()=>({[c.ErrorCode.FileInvalidType]:(0,d.sub)(Liferay.Language.get("please-enter-a-file-with-a-valid-extension-x"),[P]),[c.ErrorCode.FileTooLarge]:(0,d.sub)(Liferay.Language.get("please-enter-a-file-with-a-valid-file-size-no-larger-than-x"),[(0,d.formatStorage)(N)]),[c.ErrorCode.TooManyFiles]:Liferay.Language.get("multiple-file-upload-is-not-supported-please-enter-a-single-file")})),[N,P]),{getInputProps:k,getRootProps:A,isDragActive:W}=(0,c.useDropzone)({accept:P,maxSize:N,multiple:!1,onDropAccepted:e=>{C(""),O(e[0])},onDropRejected:e=>{var t,a,l;C(U[null==e||null===(t=e[0])||void 0===t||null===(a=t.errors)||void 0===a||null===(l=a[0])||void 0===l?void 0:l.code]||"")}});return(0,s.useEffect)((()=>{if(I){const e=(0,g.default)({file:I,fileFieldName:"imageSelectorFileName",onError:()=>{x()&&C((0,y.default)())},onProgress:z,onSuccess:e=>{x()&&(e.success?(M(e),T(!0)):C((0,y.default)(e.error,N)))},url:j});L((()=>()=>{O(null),L(null),z(null),e.abort()}))}}),[I,x,j,N]),s.default.createElement(s.default.Fragment,null,s.default.createElement(s.default.Fragment,null,s.default.createElement("div",E({},A({className:(0,u.default)("dropzone",{"dropzone-drag-active":W,"dropzone-error":_,"dropzone-uploading":R})}),{onAnimationEnd:()=>{x()&&F(!1)}}),s.default.createElement("input",E({disabled:R},k())),R?s.default.createElement(n.default.ContentRow,{className:"align-items-center",padded:!0},s.default.createElement(n.default.ContentCol,null,s.default.createElement("strong",null,Liferay.Language.get("uploading"))),s.default.createElement(n.default.ContentCol,{expand:!0},s.default.createElement(o.default,{value:R})),s.default.createElement(n.default.ContentCol,null,s.default.createElement(l.ClayButtonWithIcon,{borderless:!0,displayType:"secondary",onClick:S,symbol:"times"}))):s.default.createElement(p.default,{mimeTypeRestriction:v})),$&&s.default.createElement(r.default.FeedbackGroup,{className:"has-error"},s.default.createElement(r.default.FeedbackItem,null,s.default.createElement(r.default.FeedbackIndicator,{symbol:"exclamation-full"}),$))),D&&s.default.createElement("div",{className:"item-selector-preview-container"},s.default.createElement(f.default,E({},(0,m.default)({closeCaption:e,file:I,itemData:h,itemSelectedEventName:a,uploadItemReturnType:w}),{editImageURL:t,handleClose:()=>{T(!1)},reloadOnHide:!0}))))};t.default=w}}));
//# sourceMappingURL=SingleFileUploader.js.map