import { h } from "@stencil/core";
export class EclButton {
    constructor() {
        this.styleClass = '';
        this.type = 'submit';
        this.variant = 'primary';
        this.theme = 'ec';
        this.hideLabel = false;
        this.ariaControls = undefined;
        this.itemId = undefined;
    }
    componentDidRender() {
        const dataAttrs = Object.keys(this.el.dataset);
        if (dataAttrs) {
            dataAttrs.forEach((attr) => {
                const button = this.el.firstElementChild;
                const attrValue = this.el.dataset[attr];
                if (attrValue === '' || attrValue === attr) {
                    button.dataset[attr] = attr; // Booleans
                }
                else {
                    button.dataset[attr] = attrValue;
                }
                delete this.el.dataset[attr];
            });
        }
        if (this.el.getElementsByTagName('ecl-icon')[0] && this.el.querySelector('.ecl-icon')) {
            const slot = this.el.getElementsByTagName('ecl-icon')[0].getAttribute('slot');
            this.el.querySelector('.ecl-icon').classList.add('ecl-button__icon');
            if (slot && !this.hideLabel) {
                this.el.querySelector('.ecl-icon').classList.add(`ecl-button__${slot.substring(0, 5) + '-' + slot.substring(5)}`, `sc-ecl-button-${this.theme}`);
            }
        }
    }
    getClass() {
        return [
            `ecl-button`,
            `ecl-button--${this.variant}`,
            this.styleClass
        ].join(' ');
    }
    render() {
        return (h("button", Object.assign({ class: this.getClass(), type: this.type }, (this.ariaControls && { 'aria-controls': this.ariaControls }), (this.itemId && { id: this.itemId })), h("span", { class: "ecl-button__container" }, h("slot", { name: "icon-before" }), !this.hideLabel ?
            h("span", { class: "ecl-button__label" }, h("slot", null)) :
            h("span", { class: "ecl-u-sr-only", "data-ecl-label": true }, h("slot", null)), h("slot", { name: "icon-after" }))));
    }
    static get is() { return "ecl-button"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-button-ec.css"],
            "eu": ["./build/styles/ecl-button-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-button-ec.css"],
            "eu": ["build/styles/ecl-button-eu.css"]
        };
    }
    static get properties() {
        return {
            "styleClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "style-class",
                "reflect": false,
                "defaultValue": "''"
            },
            "type": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "type",
                "reflect": false,
                "defaultValue": "'submit'"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "variant",
                "reflect": false,
                "defaultValue": "'primary'"
            },
            "theme": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "theme",
                "reflect": false,
                "defaultValue": "'ec'"
            },
            "hideLabel": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "hide-label",
                "reflect": false,
                "defaultValue": "false"
            },
            "ariaControls": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "aria-controls",
                "reflect": false
            },
            "itemId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "item-id",
                "reflect": false
            }
        };
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-button.js.map
