/**
 * Copyright 2019 The Pennsylvania State University
 * @license Apache-2.0, see License.md for full text.
 */
import{html as t}from"../../../../../@polymer/polymer/polymer-element.js";import{HAXCMSPolymerElementTheme as e}from"../HAXCMSPolymerElementTheme.js";import{stylesFromTemplate as s}from"../../../../../@polymer/polymer/lib/utils/style-gather.js";import"../../ui-components/templates/basic-template.js";class HAXCMSUserTheme extends e{async getCSS(){return await fetch("theme/theme.css").then((t=>t.text())).then((t=>{const e=new CustomEvent("haxcms-custom-theme-template-ready",{bubbles:!0,composed:!0,cancelable:!1,detail:{css:t}});return this.dispatchEvent(e),t}))}async getHTML(){return await fetch("theme/theme.html").then((t=>t.text())).then((t=>{const e=new CustomEvent("haxcms-custom-theme-template-ready",{bubbles:!0,composed:!0,cancelable:!1,detail:{html:t}});return this.dispatchEvent(e),t}))}constructor(){super(),this.__counter=0,this.getCSS(),this.getHTML(),globalThis.addEventListener("haxcms-custom-theme-template-ready",this.templateReady.bind(this))}connectedCallback(){super.connectedCallback(),this.contentContainer=this.shadowRoot.querySelector("#contentcontainer")}static get template(){return t`
      <div id="contentcontainer">
        <div id="slot">
          <slot></slot>
        </div>
      </div>
    `}templateReady(t){if(this.__counter++,t.detail.css&&(this._css=t.detail.css),t.detail.html&&(this._html=t.detail.html),2===this.__counter){let t=globalThis.document.createElement("template");t.innerHTML=`\n      <style>\n        /**\n         * Hide the slotted content during edit mode. This must be here to work.\n         */\n        :host([edit-mode]) #slot {\n          display: none;\n        }\n        ${this._css}\n      </style>\n      ${this._html}`;const n=s(t);for(;this.shadowRoot.firstChild;)this.shadowRoot.removeChild(this.shadowRoot.firstChild);for(var e in n)t.innerHTML=n[e].outerHTML+t.innerHTML;this.__instance=this._stampTemplate(t),this.shadowRoot.appendChild(this.__instance)}}}customElements.define("haxcms-user-theme",HAXCMSUserTheme);export{HAXCMSUserTheme};