import { h, getAssetPath } from '@stencil/core';
export class EclFile {
  constructor() {
    this.theme = 'ec';
    this.styleClass = undefined;
    this.variant = 'default';
    this.downloadLabel = undefined;
    this.downloadLink = undefined;
    this.fileTitle = undefined;
    this.detailMeta = undefined;
    this.language = undefined;
    this.meta = undefined;
    this.image = undefined;
    this.imageAlt = undefined;
    this.ariaLabel = undefined;
    this.labels = undefined;
    this.taxonomies = undefined;
    this.taxonomiesLabel = undefined;
    this.eclScript = false;
  }
  getClass() {
    const styleClasses = [
      `ecl-file`,
      `ecl-file--${this.variant}`,
      this.styleClass
    ];
    return styleClasses.join(' ');
  }
  componentDidRender() {
    if (this.el.querySelector('.ecl-file__translation-list') && this.eclScript) {
      // Clean the html so that the script finds what it expects.
      const translations = this.el.querySelectorAll('.ecl-file__translation-item');
      this.el.querySelector('.ecl-file__translation-list').innerHTML = '';
      this.el.querySelector('.ecl-file__translation-list').append(...translations);
      // Load the ECL vanilla js if not already present.
      const src = getAssetPath('./build/scripts/ecl-file-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 file = new ECL.FileDownload(this.el.firstElementChild);
        file.init();
      };
      document.body.appendChild(script);
    }
  }
  getLabels() {
    const labelsArray = this.labels ? JSON.parse(this.labels) : '';
    let labelsMarkup = '';
    if (labelsArray) {
      labelsMarkup = labelsArray.map((label) => (h("div", { class: "ecl-file__label" }, h("ecl-label", { variant: label.variant, theme: this.theme }, label.label))));
    }
    return labelsMarkup;
  }
  getMeta() {
    return h("div", { class: "ecl-file__meta" }, this.meta);
  }
  getDetailedMeta() {
    const detailMetaArray = this.detailMeta ? JSON.parse(this.detailMeta) : '';
    let detailMetaMarkup = '';
    if (detailMetaArray) {
      detailMetaMarkup =
        h("div", { class: "ecl-file__detail-meta" }, detailMetaArray.map((meta) => (h("span", { class: "ecl-file__detail-meta-item" }, meta))));
    }
    return detailMetaMarkup;
  }
  getTitle() {
    return h("div", { class: "ecl-file__title" }, this.fileTitle);
  }
  getLanguage() {
    return h("div", { class: "ecl-file__language" }, this.language);
  }
  getDownload() {
    const downloadMarkup = h("ecl-link", { path: this.downloadLink, variant: "standalone" }, this.downloadLabel, h("ecl-icon", { theme: this.theme, icon: "download", size: "fluid", slot: "icon-after" }));
    return downloadMarkup;
  }
  render() {
    const isDefault = this.variant == 'default';
    return (h("div", { class: this.getClass(), "data-ecl-file": true }, h("div", { class: "ecl-file__container" }, isDefault ?
      h("ecl-icon", { icon: "file", size: this.theme === 'ec' ? '2xl' : 'm', styleClass: `ecl-file__icon sc-ecl-file-${this.theme}`, theme: this.theme }) :
      h("div", { class: "ecl-file__detail" }, h("div", { class: "ecl-file__detail-info" }, this.getLabels(), this.getDetailedMeta(), this.getTitle(), h("div", { class: "ecl-file__description" }, h("slot", null))), this.image ?
        h("img", { class: "ecl-file__image", src: this.image, alt: this.imageAlt }) : ''), this.taxonomies ?
      h("div", { class: "ecl-file__taxonomy" }, h("ecl-description-list", { theme: this.theme, variant: "horizontal" }, h("ecl-description-list-term", { theme: this.theme, "style-class": `sc-ecl-file-${this.theme}` }, this.taxonomiesLabel), h("ecl-description-list-definition", { theme: this.theme, items: this.taxonomies, type: "taxonomy", "style-class": `sc-ecl-file-${this.theme}` }))) : '', isDefault ?
      h("div", { class: "ecl-file__info" }, this.getLabels(), this.getDetailedMeta(), this.getTitle(), this.getLanguage(), this.getMeta()) :
      h("div", { class: "ecl-file__info" }, this.getLanguage(), this.getMeta()), this.getDownload()), h("slot", { name: "file-translations" })));
  }
  static get is() { return "ecl-file"; }
  static get encapsulation() { return "scoped"; }
  static get originalStyleUrls() {
    return {
      "ec": ["./build/styles/ecl-file-ec.css"],
      "eu": ["./build/styles/ecl-file-eu.css"]
    };
  }
  static get styleUrls() {
    return {
      "ec": ["./build/styles/ecl-file-ec.css"],
      "eu": ["./build/styles/ecl-file-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
      },
      "variant": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "variant",
        "reflect": false,
        "defaultValue": "'default'"
      },
      "downloadLabel": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "download-label",
        "reflect": false
      },
      "downloadLink": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "download-link",
        "reflect": false
      },
      "fileTitle": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "file-title",
        "reflect": false
      },
      "detailMeta": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "detail-meta",
        "reflect": false
      },
      "language": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "language",
        "reflect": false
      },
      "meta": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "meta",
        "reflect": false
      },
      "image": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "image",
        "reflect": false
      },
      "imageAlt": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "image-alt",
        "reflect": false
      },
      "ariaLabel": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "aria-label",
        "reflect": false
      },
      "labels": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "labels",
        "reflect": false
      },
      "taxonomies": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "taxonomies",
        "reflect": false
      },
      "taxonomiesLabel": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "taxonomies-label",
        "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-file.js.map
