import{d as f}from"./chunk-AOZYVJHK.js";import{c as w}from"./chunk-R55BXRRG.js";import{a as g}from"./chunk-DAOTUXG2.js";import{a as v,c,h,p as m}from"./chunk-HKSRVRBT.js";import{d as $}from"./chunk-L67DAW3A.js";var p=$(w()),d=v(),O=class extends f{constructor(e){super(e)}create(){this.setConfig("downloadDialogue"),super.create(),this.$element.attr("role","region"),this.$element.attr("aria-label",this.content.title),this.openCommand=g.SHOW_DOWNLOAD_DIALOGUE,this.closeCommand=g.HIDE_DOWNLOAD_DIALOGUE;let e;this.extensionHost.subscribe(this.openCommand,t=>{e=t,this.open(t)}),this.extensionHost.subscribe(this.closeCommand,()=>{e&&e.focus(),this.close()}),this.$title=d(`<div role="heading" class="heading">${this.content.title}</div>`),this.$content.append(this.$title),this.$noneAvailable=d('<div class="noneAvailable">'+this.content.noneAvailable+"</div>"),this.$content.append(this.$noneAvailable),this.$downloadOptions=d('<ol class="options"></ol>'),this.$content.append(this.$downloadOptions),this.$footer=d('<div class="footer"></div>'),this.$content.append(this.$footer),this.$termsOfUseButton=d('<a href="#">'+this.extension.data.config.content.termsOfUse+"</a>"),this.$footer.append(this.$termsOfUseButton),this.$termsOfUseButton.onPressed(()=>{this.extensionHost.publish(g.SHOW_TERMS_OF_USE)}),this.$element.hide(),this.updateTermsOfUseButton()}addEntireFileDownloadOptions(){if(this.isDownloadOptionAvailable("entireFileAsOriginal")){this.$downloadOptions.empty();let e=this.extension.helper.getCurrentCanvas(),t=!1,a=e.getRenderings();for(let n=0;n<a.length;n++){let s=a[n],o=s.getFormat(),r="";o&&(r=o.toString()),this.addEntireFileDownloadOption(s.id,p.LanguageMap.getValue(s.getLabel()),r),t=!0}if(!t){let n=!1,s=e.getContent();for(let o=0;o<s.length;o++){let i=s[o].getBody();if(i.length){let l=i[0].getFormat();l&&(this.addEntireFileDownloadOption(i[0].id,"",l.toString()),n=!0)}}n||this.addEntireFileDownloadOption(e.id,"","")}}}addEntireFileDownloadOption(e,t,a){let n;a?n=h.simplifyMimeType(a):n=this.getFileExtension(e),t||(t=this.content.entireFileAsOriginal),n&&(t+=" ("+n+")"),this.$downloadOptions.append('<li><a href="'+e+'" target="_blank" download tabindex="0">'+t+"</li>")}resetDynamicDownloadOptions(){this.renderingUrls=[],this.renderingUrlsCount=0,this.$downloadOptions.find("li.dynamic").remove()}getDownloadOptionsForRenderings(e,t,a){let n=e.getRenderings(),s=[];for(let o=0;o<n.length;o++){let r=n[o];if(r){let i=p.LanguageMap.getValue(r.getLabel(),this.extension.getLocale()),l="downloadOption"+ ++this.renderingUrlsCount;i?i+=" ({0})":i=t;let u=h.simplifyMimeType(r.getFormat().toString());i=m.format(i,u),this.renderingUrls[l]=r.id;let b=d('<li class="option dynamic"><input id="'+l+'" data-mime="'+u+'" title="'+i+'" type="radio" name="downloadOptions" tabindex="0" /><label for="'+l+'">'+i+"</label></li>");s.push({type:a,button:b})}}return s}getSelectedOption(){return this.$downloadOptions.find("li.option input:checked")}getCurrentResourceId(){let e=this.extension.helper.getCurrentCanvas(),t=e.externalResource.data.id;return t||(t=e.externalResource.data.contentLocation),t}getCurrentResourceFormat(){let e=this.getCurrentResourceId();return e?.substr(e.lastIndexOf(".")+1).toLowerCase()}updateNoneAvailable(){this.$downloadOptions.find("li:visible").length?this.$noneAvailable.hide():this.$noneAvailable.show()}updateTermsOfUseButton(){let e=this.extension.helper.getRequiredStatement();c.getBool(this.extension.data.config.options.termsOfUseEnabled,!1)&&e&&e.value?this.$termsOfUseButton.show():this.$termsOfUseButton.hide()}getFileExtension(e){let t=e.split(".").pop();return t.length>5||t.indexOf("/")!==-1?null:t}isMediaDownloadEnabled(){return this.extension.helper.isUIEnabled("mediaDownload")}isDownloadOptionAvailable(e){switch(e){case"entireFileAsOriginal":return this.isMediaDownloadEnabled()}return!0}close(){super.close()}resize(){this.setDockedPosition()}};export{O as a};
