/**
 * Copyright 2018 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{store as t}from"./haxcms-site-store.js";class HAXCMSEditorBuilder extends HTMLElement{static get tag(){return"haxcms-editor-builder"}constructor(){super(),this.windowControllers=new AbortController,globalThis.HAXCMS.requestAvailability().storePieces.editorBuilder=this,this.applyContext(),globalThis.addEventListener("haxcms-site-editor-loaded",this.editorLoaded.bind(this),{signal:this.windowControllers.signal})}connectedCallback(){super.connectedCallback&&super.connectedCallback(),this.dispatchEvent(new CustomEvent("haxcms-editor-builder-ready",{bubbles:!0,composed:!0,cancelable:!1,detail:this}))}disconnectedCallback(){this.windowControllers.abort(),super.disconnectedCallback&&super.disconnectedCallback()}editorLoaded(e){t.cmsSiteEditor.haxCmsSiteEditorUIElement||import("./haxcms-site-editor-ui.js").then((()=>{for(var e in t.cmsSiteEditor.haxCmsSiteEditorUIElement=globalThis.document.createElement("haxcms-site-editor-ui"),t.setupSlots)switch(e){case"haxcms-site-editor-ui-prefix-avatar":case"haxcms-site-editor-ui-prefix-buttons":case"haxcms-site-editor-ui-suffix-buttons":case"haxcms-site-editor-ui-main-menu":case"haxcms-site-editor-ui-topbar-character-button":for(var i in t.setupSlots[e])t.cmsSiteEditor.haxCmsSiteEditorUIElement.appendChild(t.setupSlots[e][i])}this.parentNode?this.parentNode.insertBefore(t.cmsSiteEditor.haxCmsSiteEditorUIElement,this):globalThis.document.body.appendChild(t.cmsSiteEditor.haxCmsSiteEditorUIElement),setTimeout((()=>{t.cmsSiteEditor.haxCmsSiteEditorUIElement.painting=!1}),600)}))}async applyContext(e=null){if(!this.__appliedContext){if(this.__appliedContext=!0,null==e&&(e=globalThis.HAXCMS.requestAvailability().getApplicationContext()),["php","nodejs","desktop"].includes(e)){let t=globalThis.document.createElement("script");globalThis.appSettings&&globalThis.appSettings.connectionSettings?t.src=globalThis.appSettings.connectionSettings:t.src="../../system/api/connectionSettings",await fetch(t.src).then((e=>{e.ok&&(this.__hasConnectionSettings=!0,globalThis.document.documentElement.appendChild(t))}))}if("demo"==e&&(this.__hasConnectionSettings=!0),!["published","11ty"].includes(e)&&this.__hasConnectionSettings){const i=new URL("./haxcms-editor-builder.js",import.meta.url).href+"/../";t.cmsSiteEditorBackend.tag=`haxcms-backend-${e}`,import(`${i}backends/${t.cmsSiteEditorBackend.tag}.js`).then((e=>{t.cmsSiteEditorBackend.instance||(t.cmsSiteEditorBackend.instance=globalThis.document.createElement(t.cmsSiteEditorBackend.tag),globalThis.document.body.appendChild(t.cmsSiteEditorBackend.instance))}))}}}}customElements.define(HAXCMSEditorBuilder.tag,HAXCMSEditorBuilder);export{HAXCMSEditorBuilder};