import{html as t}from"../../../../../lit/index.js";import{store as i}from"../haxcms-site-store.js";import"../../../../hax-iconset/lib/simple-hax-iconset.js";import{b64toBlob as e}from"../../../../utils/utils.js";import{MicroFrontendRegistry as n}from"../../../../micro-frontend-registry/micro-frontend-registry.js";import{HAXCMSI18NMixin as o}from"./HAXCMSI18NMixin.js";import"../../../../simple-icon/lib/simple-icon-button-lite.js";import"../../../../simple-tooltip/simple-tooltip.js";import{toJS as r}from"../../../../../mobx/dist/mobx.esm.js";import{enableServices as s}from"../../../../micro-frontend-registry/lib/microServices.js";export const PrintBranchMixin=function(a){return class extends(o(a)){constructor(){super(),s(["haxcms"]),this.t.print="Print",this.t.printPage="Print page",this.t.printingPleaseWait="Printing, please wait..",this.__printBranchLoading=!1,this.dispatchEvent(new CustomEvent("super-daemon-define-option",{bubbles:!0,cancelable:!0,composed:!0,detail:{title:this.t.printPage,icon:"icons:print",tags:["CMS","print","page"],value:{target:this,method:"printBranchOfSite"},context:"CMS",eventName:"super-daemon-element-method",path:"CMS/page/print"}}))}static get properties(){return{...super.properties,__printBranchLoading:{type:Boolean}}}PrintBranchButton(i="auto"){return t`
        ${n.has("@haxcms/siteToHtml")?t` <div
              class="print-branch-btn"
              part="${this.editMode?"edit-mode-active":""}"
            >
              <simple-icon-button-lite
                part="print-branch-btn"
                class="btn"
                icon="${this.__printBranchLoading?"hax:loading":"icons:print"}"
                @click="${this.printBranchOfSite}"
                icon-position="top"
                label="${this.__printBranchLoading?this.t.printingPleaseWait:this.t.print}"
                id="print-branch-btn"
              >
              </simple-icon-button-lite>
              <simple-tooltip for="print-branch-btn" position="${i}">
                ${this.__printBranchLoading?this.t.printingPleaseWait:this.t.print}
              </simple-tooltip>
            </div>`:""}
      `}async printBranchOfSite(t){this.__printBranchLoading=!0;var o="";globalThis.document.querySelector("base")&&(o=globalThis.document.querySelector("base").href);const s=r(i.manifest),a={type:"site",site:{file:o+"site.json",id:s.id,title:s.title,author:s.author,description:s.description,license:s.license,metadata:s.metadata,items:s.items},ancestor:r(i.activeId),link:o,magic:globalThis.__appCDN,base:o},p=await n.call("@haxcms/siteToHtml",a);if(200==p.status&&p.data){globalThis.document.createElement("a").href=globalThis.URL.createObjectURL(e(btoa(unescape(encodeURIComponent(p.data))),"text/html")),globalThis.open(globalThis.URL.createObjectURL(e(btoa(unescape(encodeURIComponent(p.data))),"text/html")),"","left=0,top=0,width=800,height=800,toolbar=0,scrollbars=0,status=0,noopener=1,noreferrer=1")}else globalThis.open(globalThis.location.href+"?format=print-page","","left=0,top=0,width=800,height=800,toolbar=0,scrollbars=0,status=0,noopener=1,noreferrer=1");this.__printBranchLoading=!1}}};