import Utils from"../../src/utils";class FileEventsClass{constructor(){}wpUploadMedia(e,t=!0){let i,a=this,l="";return new Promise((function(s,r){i=wp.media({multiple:!1,order:"DESC",orderby:"date",library:{type:"image"},title:"Select an Image"}).on("select",(()=>{let s=i.state().get("selection").first().toJSON();"image"===s.type&&(t&&a.appendMediaToCell(s,e),l=s.url)})).on("close",(()=>{setTimeout((()=>{if(l.length)return s(l)}),10)})).open()}))}appendMediaToCell(e,t){let i=e.id;t.cellData.value=i,t.cellData.html=this.getMediaElement(e),t.cellData.attachment=e,Utils.updateCell(t.cellData,t.ActionsHandlerInstance)}getMediaElement(e){let t;switch(e.type){case"image":let i=void 0!==e.sizes.thumbnail?e.sizes.thumbnail.url:e.url;t=this.getImage(i);break;case"video":t=this.getVideo(e.url,e.mime);break;case"audio":t=this.getAudio(e.url,e.mime);break;default:t=this.getLink(e.url,e.filename)}return t}getImage(e){return`<a href="${e}" class="tablesome__inputMediaPreview--link" target="_blank">\n\t\t<img class="tablesome__inputMediaPreview tablesome__inputMediaPreview--image" src="${e}" />\n\t\t</a>`}getAudio(e,t){return`<audio controls class="tablesome__inputMediaPreview tablesome__inputMediaPreview--audio">\n\t\t<source src="${e}" type="${t}">\n\t\tYour browser does not support HTML audio\n\t\t</audio>`}getVideo(e,t){return`<video controls class="tablesome__inputMediaPreview tablesome__inputMediaPreview--video">\n\t\t<source src="${e}" type="${t}">\n\t\tYour browser does not support HTML video\n\t\t</video>`}getLink(e,t){return`<a class="tablesome__inputMediaPreview tablesome__inputMediaPreview--link" href="${e}" target="_blank">${t}</a>`}}let fileEvents=new FileEventsClass;export default fileEvents;