import{LitElement as t,html as e,css as i}from"../../lit/index.js";import"../cms-hax/cms-hax.js";import{HAXStore as a}from"../hax-body/lib/hax-store.js";class WysiwygHax extends t{static get styles(){return[i`
        :host {
          display: block;
        }
      `]}render(){return e`
      <textarea
        class="${this.fieldClass}"
        id="${this.fieldId}"
        name="${this.fieldName}"
        hidden=""
      >
      ${this.bodyValue}
      </textarea
      >
      <cms-hax
        hide-message=""
        redirect-location="${this.redirectLocation}"
        update-page-data="${this.updatePageData}"
        .end-point="${this.endPoint}"
        app-store-connection="${this.appStoreConnection}"
        offset-margin="${this.offsetMargin}"
        .allowed-tags="${this.allowedTags}"
        ?open-default="${this.openDefault}"
        ?sync-body="${this.syncBody}"
        ?hide-panel-ops="${this.hidePanelOps}"
        element-align="${this.elementAlign}"
      >
      </cms-hax>
    `}static get tag(){return"wysiwyg-hax"}constructor(){super(),this.windowControllers=new AbortController;let t=this.querySelector("template");t&&(this.__importContent=t.cloneNode(!0)),this.openDefault=!1,this.elementAlign="left",this.fieldId="textarea-input-field",this.fieldName="data[content]",this.endPoint=null,this.allowedTags=[],this.redirectLocation="",this.updatePageData=""}updated(t){t.forEach(((t,e)=>{"saveButtonSelector"==e&&this[e].tagName&&this.saveButtonSelector.addEventListener("click",this.__saveClicked.bind(this))}))}static get properties(){return{openDefault:{type:Boolean,attribute:"open-default"},redirectLocation:{type:String,attribute:"redirect-location"},hidePanelOps:{type:Boolean,attribute:"hide-panel-ops"},elementAlign:{type:String,attribute:"element-align"},offsetMargin:{type:String,attribute:"offset-margin"},bodyValue:{type:String,attribute:"body-value"},allowedTags:{type:Array,attribute:"allowed-tags"},appStoreConnection:{type:String,attribute:"app-store-connection"},saveButtonSelector:{type:Object},fieldClass:{type:String,attribute:"field-class"},fieldId:{type:String,attribute:"field-id"},fieldName:{type:String,attribute:"field-name"},syncBody:{type:Boolean,attribute:"sync-body",reflect:!0},endPoint:{type:String,attribute:"end-point"},updatePageData:{type:String,attribute:"update-page-data"}}}createRenderRoot(){return this}firstUpdated(t){super.firstUpdated&&super.firstUpdated(t),this.__importContent&&this.querySelector("cms-hax").appendChild(this.__importContent)}connectedCallback(){super.connectedCallback(),globalThis.addEventListener("hax-save-body-value",this._bodyContentUpdated.bind(this),{signal:this.windowControllers.signal})}disconnectedCallback(){this.windowControllers.abort(),this.saveButtonSelector&&this.saveButtonSelector.tagName&&this.saveButtonSelector.removeEventListener("click",this.__saveClicked.bind(this)),super.disconnectedCallback()}async __saveClicked(t){a.skipExitTrap=!0,a.editMode=!1,this.dispatchEvent(new CustomEvent("hax-save",{bubbles:!0,cancelable:!0,composed:!0,detail:t.detail})),globalThis.dispatchEvent(new CustomEvent("simple-modal-hide",{bubbles:!0,cancelable:!0,detail:{}}))}async _bodyContentUpdated(t){this.bodyValue=t.detail.value}}customElements.define(WysiwygHax.tag,WysiwygHax);export{WysiwygHax};