/**
 * Copyright 2024
 * @license , see License.md for full text.
 */
import{LitElement as e,html as t,css as i}from"../../lit/index.js";class DisqusEmbed extends e{constructor(){super(),this.loadingText="Loading comments..",this.pageURL=null,this.pageIdentifier=null,this.pageTitle=null,this.shortName=null,this.lang="en"}static get properties(){return{loadingText:{type:String,attribute:"loading-text"},pageURL:{type:String,attribute:"page-url"},pageIdentifier:{type:String,attribute:"page-identifier"},pageTitle:{type:String,attribute:"page-title"},shortName:{type:String,attribute:"short-name"},lang:{type:String}}}static get styles(){return[i`
        :host {
          display: block;
          min-height: 64px;
          background-color: white;
          color: black;
          border-radius: 16px;
          border: 2px solid black;
          padding: 24px;
        }
      `]}render(){return t`<slot>${this.loadingText}</slot>`}updated(e){super.updated&&super.updated(e),e.forEach(((e,t)=>{"shortName"===t&&this[t]&&DisqusInstance.createEmbedScript(this,this.shortName),"shortName"!==t&&globalThis.DISQUS&&(clearTimeout(this._timeout),this._timeout=setTimeout((()=>{DisqusInstance.rebuildConfiguration(this,this.pageIdentifier,this.pageURL,this.pageTitle,this.lang)}),100))}))}static get tag(){return"disqus-embed"}connectedCallback(){super.connectedCallback&&super.connectedCallback(),clearTimeout(this._timeout),this._timeout=setTimeout((()=>{DisqusInstance.rebuildConfiguration(this,this.pageIdentifier,this.pageURL,this.pageTitle,this.lang)}),100)}disconnectedCallback(){for(;this.childNodes.length>0;)DisqusInstance.appendChild(this.childNodes[0]);super.disconnectedCallback&&super.disconnectedCallback()}}customElements.define(DisqusEmbed.tag,DisqusEmbed);export{DisqusEmbed};class DisqusBroker extends e{constructor(){super(),this.renderTarget=null}firstUpdated(e){super.firstUpdated&&super.firstUpdated(e),this.setAttribute("id","disqus_thread")}static get styles(){return[i`
        :host {
          display: none;
        }
      `]}render(){return t`<slot></slot>`}static get tag(){return"disqus-broker"}createEmbedScript(e,t){this.renderTarget=e,this.innerHTML="",this._embed||(this._embed=globalThis.document.createElement("script"),this._embed.setAttribute("data-timestamp",+new Date),this._embed.type="text/javascript",this._embed.async=!0,this._embed.src=`https://${t}.disqus.com/embed.js`,this.insertAdjacentElement("afterend",this._embed))}rebuildConfiguration(e,t,i,s,a){if(globalThis.DISQUS){for(this.renderTarget=e,this.innerHTML="";this.renderTarget.childNodes.length>0;)this.appendChild(this.renderTarget.childNodes[0]);setTimeout((()=>{globalThis.DISQUS.reset({reload:!0,config:function(){this.page.identifier=t,this.page.url=i,this.page.title=s,this.language=a}}),setTimeout((()=>{this.renderToTarget()}),100)}),500)}}renderToTarget(){clearTimeout(this._timeout),this._timeout=setTimeout((()=>{for(;this.childNodes.length>0;)this.renderTarget.appendChild(this.childNodes[0])}),100)}apiCallback(e){switch(e){case"onReady":case"onIdentify":this.renderToTarget();break;default:console.log(e)}}}customElements.define(DisqusBroker.tag,DisqusBroker);export{DisqusBroker};globalThis.DisqusSingleton=globalThis.DisqusSingleton||{},globalThis.DisqusSingleton.requestAvailability=()=>(!globalThis.DisqusSingleton.instance&&globalThis.document&&globalThis.document.body&&(globalThis.DisqusSingleton.instance=globalThis.document.createElement(DisqusBroker.tag),globalThis.document.body.insertAdjacentElement("afterbegin",globalThis.DisqusSingleton.instance)),globalThis.DisqusSingleton.instance);export const DisqusInstance=globalThis.DisqusSingleton.requestAvailability();globalThis.disqus_config=globalThis.disqus_config||function(){this.language="en",this.callbacks.onReady=[function(){DisqusInstance.apiCallback("onReady")}],this.callbacks.onIdentify=[function(){DisqusInstance.apiCallback("onIdentify")}],this.callbacks.afterRender=[function(){DisqusInstance.apiCallback("afterRender")}],this.callbacks.beforeComment=[function(){DisqusInstance.apiCallback("beforeComment")}],this.callbacks.onInit=[function(){DisqusInstance.apiCallback("onInit")}],this.callbacks.onNewComment=[function(){DisqusInstance.apiCallback("onNewComment")}],this.callbacks.onPaginate=[function(){DisqusInstance.apiCallback("onPaginate")}],this.callbacks.preData=[function(){DisqusInstance.apiCallback("preData")}],this.callbacks.preReset=[function(){DisqusInstance.apiCallback("preReset")}]};