/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../../core/Error.js";import{Convert3DFailedError as t,MultipleModelsError as s,NoModelError as o}from"../../../layers/graphics/sources/support/uploadAssetErrors.js";import{loadFooterActionsComponents as r,FooterActions as l}from"./FooterActions.js";import{loadPanelContentComponents as i,PanelContent as n,PanelContentSection as a}from"./PanelContent.js";import{loadCalciteComponents as c}from"../../support/componentsUtils.js";import{tsx as p,tsxFragment as d,classes as u}from"../../support/widget.js";const f="esri-editor__upload-details",m={base:f,status:`${f}__status`,titleWrapper:`${f}__title-wrapper`,title:`${f}__title`,description:`${f}__description`,loader:`${f}__loader`,iconSuccess:`${f}__icon ${f}__icon--success`,iconError:`${f}__icon ${f}__icon--error`,fileList:`${f}__file-list`,file:`${f}__file`,fileIcon:`${f}__file-icon`,fileName:`${f}__file-name`},_=()=>Promise.all([c({icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader")}),r(),i()]);function g(e){const{messages:t,key:s,upload:o}=e;return p(d,null,p(n,{key:s??"upload-details"},p(a,null,y(e))),"error"===o.state?p(l,{buttons:[{onClick:()=>o.retry(),label:t.modelUploads.error.uploadNew,iconStart:"upload-to",type:"button"}],key:"upload-details-footer-actions"}):null)}function y(e){const t=$(e);return t?p("div",{class:m.base,"data-testid":"upload-details",key:"upload-details-content"},p("div",{class:m.status,key:"status"},t.iconContent,p("div",{class:m.titleWrapper,key:"text"},p("div",{class:m.title,key:"title"},t.title),p("div",{class:m.description,key:"description"},t.description))),k(e.upload)):null}function $({helpMessage:e,messages:t,upload:s}){switch(s.state){case"pending":{const{title:e,description:o}=t.modelUploads.pending;return{title:e,description:o,iconContent:p("calcite-loader",{"aria-hidden":"true",class:m.loader,label:"",scale:"s",type:"determinate",value:Math.min(Math.round(100*s.progress),1===s.progress?100:99)})}}case"success":{const{title:s}=t.modelUploads.success;return{title:s,description:e||t.helpMessages3d.mesh,iconContent:p("calcite-icon",{class:u(m.iconSuccess),icon:"check",scale:"l"})}}case"error":{const{title:e}=t.modelUploads.error;return{title:e,description:h(s.error,t),iconContent:p("calcite-icon",{class:u(m.iconError),icon:"exclamation-mark-circle",scale:"l"})}}default:return null}}function h(r,l){if(!r)return null;const i=l.modelUploads.error.messages;switch(r.constructor){case o:return i.noModel;case s:return i.multipleModels;case t:return i.conversionFailed;case e:switch(r.name){case"gltf-loader-error":case"gltf-loader-invalid-glb":return i.loadFailed;case"gltf-loader-unsupported-feature":case"mesh-load-external:draco-not-supported":return i.unsupportedFeature;case"gltf-loader-request-error":return i.resourceRequestFailed;default:return i.default}default:return i.default}}function k(e){return p("div",{class:m.fileList,key:"file-list"},e.files.map(e=>p("div",{class:m.file,key:`file-${e.name}`},p("calcite-icon",{class:m.fileIcon,icon:b(e),scale:"s"}),p("span",{class:m.fileName},v(e.name)))))}function v(e){return e.split("/").pop()?.split("\\").pop()??""}function b(e){const t=e.name.split(".").pop()?.toLowerCase();return(t?M[t]:null)??j}const j="file",w="file-shape",C="file-image",M={glb:w,gltf:w,jpeg:C,jpg:C,png:C,svg:C,zip:"file-zip"};export{g as UploadDetails,m as css,_ as loadUploadDetailsComponents};
