import{html as t}from"../../../../../lit/index.js";import{store as o}from"../haxcms-site-store.js";import"../../../../hax-iconset/lib/simple-hax-iconset.js";import{b64toBlob as i}from"../../../../utils/utils.js";import{MicroFrontendRegistry as e}from"../../../../micro-frontend-registry/micro-frontend-registry.js";import{HAXCMSI18NMixin as a}from"./HAXCMSI18NMixin.js";import{toJS as s}from"../../../../../mobx/dist/mobx.esm.js";import{enableServices as d}from"../../../../micro-frontend-registry/lib/microServices.js";import"../../../../simple-tooltip/simple-tooltip.js";export const PDFPageMixin=function(n){return class extends(a(n)){constructor(){super(),d(["core"]),this.t.downloadPdf="Download PDF",this.t.downloadingPdfPleaseWait="Downloading PDF, please wait",this.__pdfLoading=!1,this.dispatchEvent(new CustomEvent("super-daemon-define-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{title:this.t.downloadPdf,icon:"lrn:pdf",tags:["CMS","pdf","print","page"],value:{target:this,method:"downloadPDFviaMicro"},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/page/pdf"}}))}PDFPageButton(o="auto"){return t`
        ${e.has("@core/htmlToPdf")?t` <div
              class="pdf-page-btn"
              part="${this.editMode?"edit-mode-active":""}"
            >
              <simple-icon-button-lite
                part="pdf-page-btn"
                class="btn"
                icon="${this.__pdfLoading?"hax:loading":"lrn:pdf"}"
                id="pdf-page-btn"
                label="${this.__pdfLoading?this.t.downloadingPdfPleaseWait:this.t.downloadPdf}"
                @click="${this.downloadPDFviaMicro}"
                icon-position="top"
              >
              </simple-icon-button-lite>
              <simple-tooltip for="pdf-page-btn" position="${o}">
                ${this.__pdfLoading?this.t.downloadingPdfPleaseWait:this.t.downloadPdf}
              </simple-tooltip>
            </div>`:""}
      `}static get properties(){return{...super.properties,__pdfLoading:{type:Boolean}}}async downloadPDFviaMicro(t){this.__pdfLoading=!0;let a=s(o.activeItemContent);var d="";globalThis.document.querySelector("base")&&(d=globalThis.document.querySelector("base").href);const n=await e.call("@core/htmlToPdf",{base:d,html:a});if(200==n.status&&n.data){const t=globalThis.document.createElement("a");t.href=globalThis.URL.createObjectURL(i(n.data,"application/pdf")),t.download=`${s(o.activeTitle)}.pdf`,t.target="_blank",this.appendChild(t),t.click(),this.removeChild(t)}this.__pdfLoading=!1}}};