import { h, getAssetPath } from '@stencil/core';
export class EclNewsTicker {
  constructor() {
    this.theme = 'ec';
    this.styleClass = undefined;
    this.counterLabel = undefined;
    this.srNext = undefined;
    this.srPrev = undefined;
    this.srPause = undefined;
    this.eclScript = false;
  }
  getClass() {
    return [
      `ecl-news-ticker`,
      this.styleClass
    ].join(' ');
  }
  componentDidRender() {
    const counterMax = this.el.querySelector('.ecl-news-ticker__counter--max');
    const countMax = this.el.querySelectorAll('.ecl-news-ticker__slide').length;
    counterMax.innerHTML = countMax;
    if (this.el.querySelector('.ecl-news-ticker__slides')) {
      // Clean the html so that the script finds what it expects.
      const slides = this.el.querySelectorAll('.ecl-news-ticker__slide');
      this.el.querySelector('.ecl-news-ticker__slides').innerHTML = '';
      this.el.querySelector('.ecl-news-ticker__slides').append(...slides);
    }
    if (this.el.querySelector('.ecl-news-ticker__controls')) {
      const controls = this.el.querySelectorAll('.ecl-news-ticker__controls button');
      const counter = this.el.querySelectorAll('.ecl-news-ticker__counter');
      this.el.querySelector('.ecl-news-ticker__controls').innerHTML = '';
      this.el.querySelector('.ecl-news-ticker__controls').append(...controls);
      this.el.querySelector('.ecl-news-ticker__controls').append(...counter);
    }
  }
  componentDidLoad() {
    if (this.el.querySelector('.ecl-news-ticker__slides') && this.eclScript) {
      // Load the ECL vanilla js if not already present.
      const src = getAssetPath('./build/scripts/ecl-news-ticker-vanilla.js');
      if (document.querySelector(`script[src="${src}"]`)) {
        document.querySelector(`script[src="${src}"]`).remove();
      }
      const script = document.createElement('script');
      script.src = src;
      script.onload = () => {
        const newsTicker = new ECL.NewsTicker(this.el.firstElementChild, { playSelector: '.ecl-news-ticker__play',
          pauseSelector: '.ecl-news-ticker__pause',
          prevSelector: '.ecl-news-ticker__prev',
          nextSelector: '.ecl-news-ticker__next',
        });
        newsTicker.init();
      };
      document.body.appendChild(script);
    }
  }
  render() {
    return (h("div", { class: this.getClass() }, h("div", { class: "ecl-news-ticker__container" }, h("ecl-icon", { icon: "information", size: "m", "style-class": `ecl-news-ticker__icon sc-ecl-news-ticker-${this.theme}` }), h("div", { class: "ecl-news-ticker__content" }, h("ul", { class: "ecl-news-ticker__slides" }, h("slot", null)))), h("div", { class: "ecl-news-ticker__controls" }, h("ecl-button", { styleClass: `ecl-news-ticker__prev sc-ecl-news-ticker-${this.theme}`, "data-ecl-news-ticker-prev": true, type: "default" }, h("ecl-icon", { styleClass: `ecl-news-ticker__icon-default sc-ecl-news-ticker-${this.theme}`, slot: "icon-after", icon: "corner-arrow", size: "l", color: "inverted", transform: "rotate-270", theme: this.theme }), h("span", { class: "ecl-u-sr-only" }, this.srPrev)), h("ecl-button", { styleClass: `ecl-news-ticker__next sc-ecl-news-ticker-${this.theme}`, "data-ecl-news-ticker-next": true, type: "default" }, h("ecl-icon", { styleClass: `ecl-news-ticker__icon-default sc-ecl-news-ticker-${this.theme}`, slot: "icon-after", icon: "corner-arrow", size: "l", color: "inverted", transform: "rotate-90", theme: this.theme }), h("span", { class: "ecl-u-sr-only" }, this.srNext)), h("ecl-button", { styleClass: `ecl-news-ticker__play sc-ecl-news-ticker-${this.theme}`, "data-ecl-news-ticker-play": true, type: "default" }, h("ecl-icon", { styleClass: `ecl-news-ticker__icon-default sc-ecl-news-ticker-${this.theme}`, slot: "icon-before", icon: "play", size: "l", color: "inverted", theme: this.theme }), h("ecl-icon", { styleClass: `ecl-news-ticker__icon-active sc-ecl-news-ticker-${this.theme}`, slot: "icon-after", icon: "play-filled", size: "l", color: "inverted", theme: this.theme })), h("ecl-button", { styleClass: `ecl-news-ticker__pause sc-ecl-news-ticker-${this.theme}`, "data-ecl-news-ticker-pause": true, type: "default" }, h("ecl-icon", { styleClass: `ecl-news-ticker__icon-default sc-ecl-news-ticker-${this.theme}`, slot: "icon-before", icon: "pause", size: "l", color: "inverted", theme: this.theme }), h("ecl-icon", { styleClass: `ecl-news-ticker__icon-active sc-ecl-news-ticker-${this.theme}`, slot: "icon-after", icon: "pause-filled", size: "l", color: "inverted", theme: this.theme }), h("span", { class: "ecl-u-sr-only" }, this.srPause)), h("div", { class: "ecl-news-ticker__counter" }, h("span", { class: "ecl-news-ticker__counter--current" }, "1"), ` ${this.counterLabel} `, h("span", { class: "ecl-news-ticker__counter--max" })))));
  }
  static get is() { return "ecl-news-ticker"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() {
    return {
      "ec": ["./build/styles/ecl-news-ticker-ec.css"],
      "eu": ["./build/styles/ecl-news-ticker-eu.css"]
    };
  }
  static get styleUrls() {
    return {
      "ec": ["./build/styles/ecl-news-ticker-ec.css"],
      "eu": ["./build/styles/ecl-news-ticker-eu.css"]
    };
  }
  static get assetsDirs() { return ["build"]; }
  static get properties() {
    return {
      "theme": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "theme",
        "reflect": false,
        "defaultValue": "'ec'"
      },
      "styleClass": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "style-class",
        "reflect": false
      },
      "counterLabel": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "counter-label",
        "reflect": false
      },
      "srNext": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "sr-next",
        "reflect": false
      },
      "srPrev": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "sr-prev",
        "reflect": false
      },
      "srPause": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "sr-pause",
        "reflect": false
      },
      "eclScript": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "ecl-script",
        "reflect": false,
        "defaultValue": "false"
      }
    };
  }
  static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-news-ticker.js.map
