"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var a=require("../../_virtual/jsx-runtime.js"),j=require("react"),l=require("./styles.js"),u=require("../Button/index.js"),d=require("./utils.js"),f=require("./FileInfoWrapper.js"),z=require("./UploaderContainerWrapper.js"),v=require("../../utils/index.js");function O({label:R,uploaderTitle:y,maxSizeDescription:E,uploadFileBtnText:b="Browse",removeFileBtnText:k="Remove",retryUploadBtnText:C="Retry",cancelBtnText:I="Cancel",assistText:F,optionalText:h,fileType:q="*",successMessage:U,errorMessage:e,width:W,getFileCallback:B,removeFileCallback:$,cancelFileCallback:w,file:t,shouldDisplayThumbnail:c=!1,loading:i,...o}){const x=Date.now(),n=j.useRef(null),p=`uploader_${x}`,m=`file_${x}`,r=v.getId(`${o["data-testid"]}-uploader`),s=v.getId(`${o["data-trackid"]}-uploader`);return j.useEffect(()=>{d.getImageUrlFromFile({file:t,fileId:m})},[JSON.stringify(t)]),a.jsxRuntimeExports.jsxs(z.UploaderContainerWrapper,{"data-testid":r("container"),"data-trackid":s("container"),width:W,optionalText:h,assistText:F,label:R,children:[a.jsxRuntimeExports.jsx("input",{id:p,"data-testid":r("input"),type:"file",ref:n,onChange:B,name:"uploader",multiple:!1,accept:q,style:{display:"none"},onClick:()=>{n!=null&&n.current&&(n.current.value="")}}),a.jsxRuntimeExports.jsxs(l.UploaderWrapper,{hasFile:!!t,"data-testid":r("wrapper"),"data-trackid":s("wrapper"),"aria-label":o["aria-label"],shouldDisplayThumbnail:c,children:[a.jsxRuntimeExports.jsx(f.FileInfoWrapper,{file:t,uploaderTitle:y,maxSizeDescription:E,loading:i,successMessage:U,errorMessage:e}),a.jsxRuntimeExports.jsxs(l.ActionButtonsWrapper,{children:[!e&&!t&&i&&a.jsxRuntimeExports.jsx(u.Button,{variant:"secondary",size:"small-expressive",onClick:w,"aria-label":"Cancel",children:I}),!e&&!t&&!i&&a.jsxRuntimeExports.jsx(u.Button,{variant:"secondary",size:"small-expressive","aria-label":"Upload","data-testid":r("upload-button"),"data-trackid":s("upload-button"),onClick:()=>d.openFileExplorer({inputId:p,file:t,errorMessage:e}),children:b}),(e||t)&&!i&&a.jsxRuntimeExports.jsx(u.Button,{variant:"secondary",size:"small-expressive","data-testid":r(e?"retry-button":"remove-button"),"data-trackid":s(e?"retry-button":"remove-button"),"aria-label":e?"Retry":"Remove",onClick:_=>{_.stopPropagation(),$(),e&&d.openFileExplorer({inputId:p,file:t,errorMessage:e})},children:e?C:k})]})]}),c&&t&&d.isImageFile(t)&&!e&&a.jsxRuntimeExports.jsx(l.FileContainer,{children:a.jsxRuntimeExports.jsx("img",{id:m,"data-testid":r("thumbnail"),src:"@jet-pie/react/src/components/Uploader/index",alt:t&&typeof t!="string"?t.name:""})})]})}exports.Uploader=O;
