import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";const{prefix:prefix}=config,name=`${prefix}-attachments`;let Attachments=class extends SuperComponent{constructor(){super(...arguments),this.options={multipleSlots:!0},this.properties=Object.assign(Object.assign({},props),{inChat:{type:Boolean,value:!1}}),this.data={classPrefix:name,files:[]},this.observers={items(){this.setFiles()}},this.methods={onFileWrapTap(e){var i;const{index:t}=e.currentTarget.dataset||{},o=null===(i=this.data.files)||void 0===i?void 0:i[t];o&&this.handleFileClick(o)},onRemoveTap(e){var i;const{index:t}=e.currentTarget.dataset||{},o=null===(i=this.data.files)||void 0===i?void 0:i[t];"function"==typeof(null==e?void 0:e.stopPropagation)&&e.stopPropagation(),void 0!==o&&this.handleRemove(o,t)},handleFileClick(e){this.data.imageViewer&&"image"===e.fileType&&wx.previewImage({urls:[e.url]}),this.triggerEvent("fileClick",{item:e})},handleRemove(e,i){this.triggerEvent("remove",{item:e,index:i})},renderDesc(e){const i=e.size||0;let t,o;if(i<1024)t=i,o="B";else if(i<1048576){const e=i/1024;t=e%1==0?e:e.toFixed(2),o="KB"}else{const e=i/1048576;t=e%1==0?e:e.toFixed(2),o="MB"}return`${t} ${o}`},renderIcon(e){const i={file:{name:"file-zip-filled",color:"#E37318"},video:{name:"video-filled",color:"#D54941"},pdf:{name:"file-pdf-filled",color:"#D54941"},doc:{name:"file-word-filled",color:"#0052d9"},excel:{name:"file-excel-filled",color:"#2BA471"},ppt:{name:"file-powerpoint-filled",color:"#E37318"},audio:{name:"video-filled",color:"#D54941"}};return i[e.fileType]||i.file},renderFileType(e){if(e.fileType)return e.fileType;if(["image","video","audio","pdf","doc","ppt","txt","excel"].includes(e.type))return e.fileType;const i=e.url||"",t=i.lastIndexOf(".");return{jpg:"image",jpeg:"image",png:"image",gif:"image",bmp:"image",webp:"image",mp4:"video",mov:"video",avi:"video",mkv:"video",webm:"video",mp3:"audio",wav:"audio",ogg:"audio",aac:"audio",pdf:"pdf",doc:"doc",docx:"doc",ppt:"ppt",pptx:"ppt",xls:"excel",xlsx:"excel",txt:"txt"}[-1!==t?i.substring(t+1).toLowerCase():""]||""},renderExtension(e){if(e.extension)return e.extension;return e.extension||(e.url?e.url.split(".").pop().toLowerCase():"")},setFiles(){this.setData({files:this.properties.items.map(e=>Object.assign(Object.assign({},e),{fileType:this.data.renderFileType(e),desc:this.data.renderDesc(e),fileIcon:this.data.renderIcon(e)}))})}},this.lifetimes={created(){this.data.handleFileClick=this.handleFileClick.bind(this),this.data.handleRemove=this.handleRemove.bind(this),this.data.renderDesc=this.renderDesc.bind(this),this.data.renderIcon=this.renderIcon.bind(this),this.data.renderFileType=this.renderFileType.bind(this),this.data.renderExtension=this.renderExtension.bind(this)},attached(){this.setFiles()},detached(){}}}};Attachments=__decorate([wxComponent()],Attachments);export default Attachments;