import { Component, Host, h, Prop, Watch } from '@stencil/core';
export class UxplArchive {
  async urlValueChanged(newValue, oldValue) {
    if (newValue !== oldValue) {
      this.articleHtml = await this.fetchArchive(this.url);
    }
  }
  async authValueChanged(newValue, oldValue) {
    if (newValue !== oldValue) {
      this.articleHtml = await this.fetchArchive(this.url);
    }
  }
  async componentWillLoad() {
    if (this.url) {
      this.articleHtml = await this.fetchArchive(this.url);
    }
  }
  async fetchArchive(url) {
    let response = await fetch(url, {
      method: 'GET',
      headers: this.auth ? { "Authorization": "Bearer: " + this.auth } : undefined
    });
    let article = await response.text();
    return article;
  }
  render() {
    return (h(Host, null,
      h("article", { class: "article-container", part: "article", innerHTML: this.articleHtml })));
  }
  static get is() { return "uxpl-archive"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["uxpl-archive.css"]
  }; }
  static get styleUrls() { return {
    "$": ["uxpl-archive.css"]
  }; }
  static get properties() { return {
    "url": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "url",
      "reflect": false
    },
    "auth": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "auth",
      "reflect": false
    }
  }; }
  static get watchers() { return [{
      "propName": "url",
      "methodName": "urlValueChanged"
    }, {
      "propName": "auth",
      "methodName": "authValueChanged"
    }]; }
}
