text: import{html,PolymerElement}from"../../@polymer/polymer/polymer-element.js";import{FlattenedNodesObserver}from"../../@polymer/polymer/lib/utils/flattened-nodes-observer.js";import"../../@polymer/iron-ajax/iron-ajax.js";import"../h-a-x/h-a-x.js";import"../simple-toast/simple-toast.js";class CmsHax extends PolymerElement{static get template(){return html`
        <style>
          :host {
            display: block;
            font-size: 16px;
            box-sizing: content-box;
          }
        </style>
        <iron-ajax
          id="pageupdateajax"
          url="[[endPoint]]"
          method="[[method]]"
          body="[[updatePageData]]"
          content-type="application/json"
          handle-as="json"
          on-response="_handleUpdateResponse"
        ></iron-ajax>
        <h-a-x app-store$="[[appStoreConnection]]"></h-a-x>
      `}static get tag(){return"cms-hax"}static get observers(){return["_noticeTagChanges(openDefault, allowedTags, hideExportButton, hidePanelOps, hidePreferencesButton, align)"]}static get properties(){return{openDefault:{type:Boolean,reflectToAttribute:!0,value:!1},hideExportButton:{type:Boolean,value:!0},hidePanelOps:{type:Boolean,value:!1},hidePreferencesButton:{type:Boolean,value:!1},align:{type:String,value:"right"},allowedTags:{type:Array},endPoint:{type:String},method:{type:String,value:"PUT"},updatePageData:{type:String},appStoreConnection:{type:Object},editMode:{type:Boolean,reflectToAttribute:!0},syncBody:{type:Boolean,value:!1},bodyValue:{type:String,value:""},hideMessage:{type:Boolean,value:!1},redirectLocation:{type:String},redirectOnSave:{type:Boolean,computed:"_computeRedirectOnSave(redirectLocation)"},activeHaxBody:{type:Object,observer:"_activeHaxBodyUpdated"},__imported:{type:Boolean,value:!1}}}_activeHaxBodyUpdated(newValue,oldValue){if(null!=newValue&&!this.__imported){this.__imported=!0;let children=this.querySelector("template");null!=children&&newValue.importContent(children.innerHTML)}}_computeRedirectOnSave(redirectLocation){return void 0!==redirectLocation}_attachDom(dom){this.appendChild(dom)}_noticeTagChanges(openDefault,allowedTags,hideExportButton,hidePanelOps,hidePreferencesButton,align){window.HaxStore.ready&&(allowedTags&&(window.HaxStore.instance.validTagList=allowedTags),window.HaxStore.instance.haxPanel.hideExportButton=hideExportButton,window.HaxStore.instance.haxPanel.hidePanelOps=hidePanelOps,window.HaxStore.instance.haxPanel.hidePreferencesButton=hidePreferencesButton,window.HaxStore.instance.haxPanel.align=align,openDefault&&window.HaxStore.write("editMode",openDefault,this))}_storeReady(e){setTimeout(()=>{this._noticeTagChanges(this.openDefault,this.allowedTags,this.hideExportButton,this.hidePanelOps,this.hidePreferencesButton,this.align)},250)}constructor(){super(),import("./lib/cms-token.js"),import("./lib/cms-block.js"),import("./lib/cms-views.js"),import("./lib/cms-entity.js")}disconnectedCallback(){this._observer&&(this._observer.disconnect(),this._observer=null),window.removeEventListener("hax-store-ready",this._storeReady.bind(this)),window.removeEventListener("hax-save",this._saveFired.bind(this)),super.disconnectedCallback()}connectedCallback(){super.connectedCallback(),window.addEventListener("hax-store-property-updated",this._haxStorePropertyUpdated.bind(this)),window.addEventListener("hax-store-ready",this._storeReady.bind(this)),window.SimpleToast.requestAvailability(),this.__lock=!1,window.addEventListener("hax-save",this._saveFired.bind(this)),this.syncBody&&(this._observer=FlattenedNodesObserver(window.HaxStore.instance.activeHaxBody,info=>{this.__lock||(this.__lock=!0,this.dispatchEvent(new CustomEvent("hax-body-content-changed",{bubbles:!0,cancelable:!0,composed:!0,detail:window.HaxStore.instance.activeHaxBody.haxToContent()})),setTimeout(()=>{this.__lock=!1},100))}))}_haxStorePropertyUpdated(e){e.detail&&void 0!==e.detail.value&&e.detail.property&&("object"==typeof e.detail.value&&this.set(e.detail.property,null),this.set(e.detail.property,e.detail.value),this.notifyPath(e.detail.property))}_saveFired(e){this.updatePageData=window.HaxStore.instance.activeHaxBody.haxToContent(),this.$.pageupdateajax.generateRequest()}_handleUpdateResponse(e){if(!this.hideMessage){const evt=new CustomEvent("simple-toast-show",{bubbles:!0,cancelable:!0,composed:!0,detail:{text:"Saved!",duration:3e3}});this.dispatchEvent(evt),this.redirectOnSave&&setTimeout(()=>{window.location=this.redirectLocation},500)}}}window.customElements.define(CmsHax.tag,CmsHax);export{CmsHax};