"use strict";(this.webpackChunk_tsmesolutions_cubes_initiatives=this.webpackChunk_tsmesolutions_cubes_initiatives||[]).push([[2145],{62145:(e,t,o)=>{o.r(t),o.d(t,{default:()=>m});var a=o(24590);const l={modelValue:Array,localFiles:Array,uploadApi:Function||Promise,hasTrigger:Boolean,readonly:Boolean,isEvidence:Boolean,modified:{type:Boolean,default:!1}};var r=o(90726),i=o(91123),n=o(19244);const s={key:0,class:"d-block text-danger mb-2"},d={key:0},u={key:1},c=(0,a.defineComponent)({__name:"uploader",props:l,emits:["update:modelValue","get-local-files","get-upload-state"],setup(e,t){let{expose:o,emit:l}=t;const c=e,m=l,p=r.IoC.DI().resolve(n.St.AppService.key),v=r.IoC.DI().resolve(n.St.InitiativeAttachmentService.key),g=r.IoC.DI().resolve(n.St.InitiativeProgressEvidencesService.key),f=(0,a.toRef)((0,i.useTranslation)(p),"tGlobal"),k=p?.application.config.maxUploadSizeMB,y=p?.application.config.maxFileUploadSizeMB,h=(0,a.toRef)(c,"localFiles"),E=(0,a.toRef)(c,"modified"),C=(0,a.ref)(h.value),I=(0,a.ref)(),S=(0,a.ref)({trigger:()=>{},remove:()=>{},onServer:void 0,pendingItems:void 0});(0,a.watch)(()=>[S.value?.onServer,h.value],e=>{let[t,o]=e,a=[];const l=t.map(e=>e.documentID);h.value?.length&&(a=h.value.filter(e=>isNaN(e.id)).map(e=>e.id)),m("update:modelValue",[...a,...l])},{deep:!0}),(0,a.watch)(()=>C.value,e=>m("get-local-files",e)),(0,a.watch)(()=>S.value.pendingItems,e=>m("get-upload-state",!!e.filter(e=>e.state!=i.UploadStateEnum.FAILED).length));const B=(0,a.computed)(()=>C.value.some(e=>!e.valid)),_=e=>S.value=e;return o({localFiles:C,uploadTrigger:()=>S.value.trigger(),hasInvalidFiles:B}),(e,t)=>{const o=(0,a.resolveComponent)("v-upload-item"),l=(0,a.resolveComponent)("v-upload"),n=(0,a.resolveDirective)("fake-link");return(0,a.openBlock)(),(0,a.createBlock)(l,{modelValue:C.value,"onUpdate:modelValue":t[0]||(t[0]=e=>C.value=e),ref_key:"uploaderComposionInstanceRef",ref:I,"register-uploader":_,mode:"multiAppend",api:e.uploadApi,readonly:e.readonly,"size-mb":(0,a.unref)(k),"file-size-mb":(0,a.unref)(y),"has-trigger":e.hasTrigger,state:S.value.sizeError?(0,a.unref)(i.ValidationStateEnum).invalid:(0,a.unref)(i.ValidationStateEnum).unset,auto:"",class:"mt-2"},{accessories:(0,a.withCtx)(()=>[(0,a.renderSlot)(e.$slots,"error",{sizeErrorMessage:I.value?.sizeError},()=>[I.value?.sizeError||I.value?.extError.length?((0,a.openBlock)(),(0,a.createElementBlock)("small",s,[I.value?.sizeError?((0,a.openBlock)(),(0,a.createElementBlock)("strong",d,(0,a.toDisplayString)(I.value?.sizeError),1)):((0,a.openBlock)(),(0,a.createElementBlock)("strong",u,(0,a.toDisplayString)(I.value?.extError.first.first()),1))])):(0,a.createCommentVNode)("v-if",!0)])]),item:(0,a.withCtx)(t=>{let{item:l,uploadFile:i}=t;return[(0,a.createVNode)(o,{item:l,readonly:e.readonly,size:"sm",onItem_upload:e=>i(l),onItem_remove:e=>S.value.remove(l)},{name:(0,a.withCtx)(()=>[(0,a.withDirectives)(((0,a.openBlock)(),(0,a.createBlock)((0,a.resolveDynamicComponent)(l.id<0?"span":E.value?"s":"a"),{class:(0,a.normalizeClass)(["text-truncate",{"text-dark":l.id<0,"text-muted":E.value}]),title:l.name,onClick:e=>l.id<0?(0,a.unref)(r.NOOP):(e=>{try{c.isEvidence?g.downloadAsync(e):v.downloadAsync(e)}catch(e){p.error(f.value.requestError,void 0,"download@uploader")}})(l.id)},{default:(0,a.withCtx)(()=>[(0,a.createTextVNode)((0,a.toDisplayString)(l.name),1)]),_:2},1032,["class","title","onClick"])),[[n]])]),_:2},1032,["item","readonly","onItem_upload","onItem_remove"])]}),_:3},8,["modelValue","api","readonly","size-mb","file-size-mb","has-trigger","state"])}}}),m=c}}]);
//# sourceMappingURL=8038b4555ad3a537ec98.js.map