import { Component, Host, h, Prop } from '@stencil/core';
export class DisqusComments {
  componentDidLoad() {
    const existingScript = document.getElementById('disqus-embed-script');
    const siteId = this.siteId;
    const siteUrl = this.url;
    const init = () => {
      console.log('DISQUS INIT');
      window.DISQUS.reset({
        reload: true,
        config: function () {
          console.log('DISQUS CONFIG', siteId, siteUrl, document.title);
          this.page.identifier = siteId;
          this.page.url = siteUrl;
          this.page.title = document.title;
          this.language = 'en';
        }
      });
    };
    if (!existingScript) {
      this.scriptEl = document.createElement('script');
      this.scriptEl.id = 'disqus-embed-script';
      this.scriptEl.type = 'text/javascript';
      this.scriptEl.async = true;
      this.scriptEl.src = `https://${this.siteId}.disqus.com/embed.js`;
      this.scriptEl.setAttribute('data-timestamp', '' + +new Date());
      this.scriptEl.addEventListener('load', () => {
        setTimeout(() => {
          init();
        }, 100);
      });
      document.body.appendChild(this.scriptEl);
      const disqusScript = document.createElement('script');
      disqusScript.id = 'dsq-count-scr';
      disqusScript.async = true;
      disqusScript.src = `//${this.siteId}.disqus.com/count.js`;
      this.disqusScriptEl = disqusScript;
      document.body.appendChild(disqusScript);
    }
    else {
      setTimeout(() => {
        init();
      }, 100);
    }
  }
  render() {
    return (h(Host, null,
      h("div", { id: "disqus_thread" }),
      h("noscript", null,
        "Please enable JavaScript to view the",
        ' ',
        h("a", { href: "https://disqus.com/?ref_noscript" }, "comments powered by Disqus."))));
  }
  static get is() { return "disqus-comments"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() { return {
    "$": ["disqus-comments.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["disqus-comments.css"]
  }; }
  static get properties() { return {
    "url": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "You're page's canonical URL. For example: `https://mysite.com/some-section/this-page`"
      },
      "attribute": "url",
      "reflect": false
    },
    "siteId": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": "Your site's ID in Disqus. You can find this by logging in to disqus and \nlooking at the subdomain used. For example, the framework blog's disqus\nadmin page is `https://ionic.disqus.com/admin/`, so the siteId is `ionic`."
      },
      "attribute": "site-id",
      "reflect": false
    }
  }; }
}
