import { h } from "@stencil/core";
import getAssetPath from "../../utils/assetPath";
export class EclMessage {
    constructor() {
        this.theme = 'ec';
        this.variant = 'info';
        this.styleClass = undefined;
        this.messageTitle = undefined;
        this.closeLabel = undefined;
        this.eclScript = false;
        this.withClose = true;
    }
    getClass() {
        return [
            `ecl-message`,
            `ecl-message--${this.getVariant()}`,
            this.styleClass
        ].join(' ');
    }
    getVariant() {
        return this.variant === 'information' ? 'info' : this.variant;
    }
    componentDidRender() {
        if (this.eclScript) {
            const src = getAssetPath('./build/scripts/ecl-message-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 message = new ECL.Message(this.el.firstElementChild);
                message.init();
            };
            document.body.appendChild(script);
        }
    }
    render() {
        return (h("div", { class: this.getClass(), "data-ecl-message": true, role: "alert" }, h("ecl-icon", { icon: this.variant, size: this.theme === 'ec' ? 'l' : 'm', "style-class": `ecl-message__icon sc-ecl-message-${this.theme}` }), h("div", { class: "ecl-message__content" }, this.withClose ?
            h("ecl-button", { variant: "ghost", type: "button", "style-class": `ecl-message__close sc-ecl-message-${this.theme}`, "data-ecl-message-close": true }, this.closeLabel, h("ecl-icon", { slot: "icon-after", icon: "close-filled", theme: this.theme, "style-class": "ecl-button__icon ecl-button__icon--after" })) : '', this.messageTitle ?
            h("div", { class: "ecl-message__title" }, this.messageTitle)
            : '', h("div", { class: "ecl-message__description" }, h("slot", null)))));
    }
    static get is() { return "ecl-message"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-message-ec.css"],
            "eu": ["./build/styles/ecl-message-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-message-ec.css"],
            "eu": ["build/styles/ecl-message-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'"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "variant",
                "reflect": false,
                "defaultValue": "'info'"
            },
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "style-class",
                "reflect": false
            },
            "messageTitle": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "message-title",
                "reflect": false
            },
            "closeLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "close-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"
            },
            "withClose": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "with-close",
                "reflect": false,
                "defaultValue": "true"
            }
        };
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-message.js.map
