import { h } from "@stencil/core";
import FileDownload from "@ecl/file";
export class EclFile {
    constructor() {
        this.elId = `ecl-file-${Math.random().toString(36).slice(2, 10)}`;
        this.variant = 'default';
        this.downloadAttribute = false;
        this.downloadId = `${this.elId}-link`;
        this.downloadLabelId = `${this.elId}-link-label`;
        this.fileTitleId = `${this.elId}-title`;
        this.noScript = false;
    }
    getClass() {
        const styleClasses = [
            `ecl-file`,
            `ecl-file--${this.variant}`,
            this.styleClass
        ];
        return styleClasses.join(' ');
    }
    componentWillLoad() {
        var _a;
        this.theme = (_a = document.documentElement.getAttribute('data-ecl-theme')) !== null && _a !== void 0 ? _a : (this.theme || 'ec');
    }
    componentDidLoad() {
        const list = this.el.querySelector('.ecl-file__translation-list');
        if (list && !this.noScript) {
            // Clean the html so that the script finds what it expects.
            const button = this.el.querySelector('.ecl-file__translation-toggle');
            if (button) {
                button.parentElement.remove();
                this.el.querySelector('.ecl-file__translation-container').prepend(button);
            }
            const translations = this.el.querySelectorAll('.ecl-file__translation-item');
            list.innerHTML = '';
            list.append(...translations);
            ;
            window.ECL = window.ECL || {};
            ECL.FileDownload = FileDownload;
            const file = new FileDownload(this.el.firstElementChild);
            file.init();
        }
    }
    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() {
        if (!this.fileTitlePath) {
            return h("div", { class: "ecl-file__title", id: this.fileTitleId }, this.fileTitle);
        }
        else {
            return h("div", { class: "ecl-file__title", id: this.fileTitleId }, h("ecl-link", { variant: "standalone", path: this.fileTitlePath }, this.fileTitle));
        }
    }
    getLanguage() {
        return h("div", { class: "ecl-file__language" }, this.language);
    }
    getDownload() {
        const downloadMarkup = h("ecl-link", Object.assign({ path: this.downloadLink, variant: "standalone", "aria-label": this.ariaLabel, "style-class": "ecl-file__download", id: this.downloadId }, (this.downloadAttribute ? { download: true } : {})), 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", { key: 'd47a2c82d72e48d5c3e3bbfb4950403b8c432149', class: this.getClass(), id: this.elId, "data-ecl-file": true }, h("div", { key: '9806b0d7b1a047db66a3b731cbe7501a47da07c4', class: "ecl-file__container" }, isDefault &&
            h("ecl-icon", { key: 'aa854236740f58bb45858fd3ec5091b201d49ec3', icon: "file", size: this.theme === 'ec' ? '2xl' : 'm', styleClass: `ecl-file__icon sc-ecl-file-${this.theme}`, theme: this.theme }), !isDefault && this.image &&
            h("ecl-picture", { key: '24d5b475f8b68bfaef7660a90b228e6f045367ac', image: this.image, imageAlt: this.imageAlt, imgClass: `ecl-file__image sc-ecl-file-${this.theme}`, styleClass: `ecl-file__picture sc-ecl-file-${this.theme}` }, h("slot", { key: 'ec39f4534da6675cd08614c434b9fcddb5597b17', name: "sources" })), !isDefault &&
            h("div", { key: '152543a3106a5d0899b7d2aa6bccea6a1b554914', class: "ecl-file__info" }, this.getLabels(), this.getDetailedMeta(), this.getTitle(), h("div", { key: '3576fd999d58c58e2bd11ec3f7f4460dc3bac959', class: "ecl-file__description" }, h("slot", { key: 'dd35f075998805721b53ebcdc46c7fd516602b24' })), this.taxonomies &&
                h("div", { key: 'b980c4245e0721b90c1dd8eea9384804a7646f87', class: "ecl-file__taxonomy" }, h("ecl-description-list", { key: 'a9d6c038acc048fff84a857496c1841221dc7b35', theme: this.theme, variant: "horizontal" }, h("ecl-description-list-term", { key: '9a3fc1abfbb0b27e1b5ec6b281dab21937073bc9', theme: this.theme, "style-class": `sc-ecl-file-${this.theme}` }, this.taxonomiesLabel), h("ecl-description-list-definition", { key: '8595ebc81a9dfa7086d9d6d05b2d194b6470bc2e', theme: this.theme, items: this.taxonomies, type: "taxonomy", "style-class": `sc-ecl-file-${this.theme}` })))), isDefault &&
            h("div", { key: 'c257fc1e87fef7f8b3c5957b51c051a51fb31ef4', class: "ecl-file__info" }, this.getTitle())), h("div", { key: '1d4a5b79c65cb23184460a7454fc6e0aaeb33ef7', class: "ecl-file__footer" }, this.getLanguage(), this.getMeta(), h("div", { key: '09c6101b31d464e163737e95b2158b3b2da62d58', class: "ecl-file__action" }, h("slot", { key: '01da9543e7dbb514dcc8dde0fe367f6d18c93582', name: "ecl-file-preview" }), this.getDownload())), h("slot", { key: 'fc61371ac1aec55aedd5e9b4f5ec8c08165307fe', 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 properties() {
        return {
            "elId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "el-id",
                "defaultValue": "`ecl-file-${Math.random().toString(36).slice(2, 10)}`"
            },
            "theme": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "theme"
            },
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "style-class"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "'default'"
            },
            "downloadAttribute": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download-attribute",
                "defaultValue": "false"
            },
            "downloadId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download-id",
                "defaultValue": "`${this.elId}-link`"
            },
            "downloadLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download-label"
            },
            "downloadLabelId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download-label-id",
                "defaultValue": "`${this.elId}-link-label`"
            },
            "downloadLink": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "download-link"
            },
            "fileTitle": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "file-title"
            },
            "fileTitleId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "file-title-id",
                "defaultValue": "`${this.elId}-title`"
            },
            "fileTitlePath": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "file-title-path"
            },
            "detailMeta": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "detail-meta"
            },
            "language": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "language"
            },
            "meta": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "meta"
            },
            "image": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "image"
            },
            "imageAlt": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "image-alt"
            },
            "ariaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "aria-label"
            },
            "labels": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "labels"
            },
            "taxonomies": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "taxonomies"
            },
            "taxonomiesLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "taxonomies-label"
            },
            "noScript": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "no-script",
                "defaultValue": "false"
            }
        };
    }
    static get elementRef() { return "el"; }
}
