import { h } from "@stencil/core";
export class EclFormGroup {
    constructor() {
        this.styleClass = '';
        this.invalid = false;
        this.required = false;
        this.requiredText = '*';
        this.hideLabel = false;
        this.labelTag = 'label';
        this.tag = 'div';
        this.invalidIcon = 'error';
    }
    getClass() {
        return [
            `ecl-form-group`,
            this.styleClass
        ].join(' ');
    }
    componentWillLoad() {
        var _a;
        this.theme = (_a = document.documentElement.getAttribute('data-ecl-theme')) !== null && _a !== void 0 ? _a : (this.theme || 'ec');
    }
    componentDidRender() {
        if (this.hideLabel) {
            const inputs = this.el.querySelectorAll('ecl-input');
            if (inputs.length === 1 && (inputs[0].getAttribute('type') === 'checkbox' || inputs[0].getAttribute('type') === 'radio')) {
                const label = inputs[0].querySelector('.ecl-checkbox__text') || inputs[0].querySelector('.ecl-radio__text');
                if (label) {
                    const span = document.createElement('span');
                    if (this.required) {
                        span.className = `ecl-form-label__required sc-ecl-form-group-${this.theme}`;
                        span.textContent = this.requiredText;
                    }
                    else if (this.optionalText) {
                        span.className = `ecl-form-label__optional sc-ecl-form-group-${this.theme}`;
                        span.textContent = this.optionalText;
                    }
                    if (span.textContent) {
                        label.after(span);
                    }
                }
            }
        }
    }
    render() {
        return (h(this.tag, { key: '165f3135354db14140c9013169917041c43c30a5', class: this.getClass(), "aria-describedby": this.helperId }, this.label ?
            h(this.labelTag, Object.assign({ class: `ecl-form-label ${this.invalid ? 'ecl-form-label--invalid' : ''} ${this.hideLabel ? 'ecl-form-label--hidden' : ''} ${this.labelClass || ''}` }, (this.ariaLabelRequired ? { 'aria-label': this.ariaLabelRequired } : {})), this.label, this.required && this.requiredText ? (h("span", Object.assign({ class: "ecl-form-label__required", role: "note" }, (this.ariaLabelRequired ? { 'aria-label': this.ariaLabelRequired } : {})), this.requiredText)) : '', !this.required && this.optionalText ?
                h("span", Object.assign({ class: "ecl-form-label__optional", role: "note" }, (this.ariaLabelOptional ? { 'aria-label': this.ariaLabelOptional } : {})), this.optionalText) : '', (this.labelTag === 'legend' && this.helperText) &&
                h("div", { class: "ecl-help-block--hidden" }, this.helperText), (this.labelTag === 'legend' && this.invalidText) &&
                h("div", { class: "ecl-feedback-message--hidden" }, this.invalidText)) : '', this.helperText ?
            h("div", Object.assign({ class: "ecl-help-block" }, (this.labelTag === 'legend' ? { 'aria-hidden': 'true' } : {})), this.helperText) : '', h("slot", { key: 'b7e68b9eb3b269947496380683180e9c01e61ea4' }), this.invalid && this.invalidText ?
            h("div", Object.assign({ class: "ecl-feedback-message" }, (this.labelTag === 'legend' ? { 'aria-hidden': 'true' } : {})), this.invalidIcon ?
                h("ecl-icon", { styleClass: `ecl-feedback-message__icon sc-ecl-form-group-${this.theme}`, icon: this.invalidIcon, size: "xs" }) : '', this.invalidText) : ''));
    }
    static get is() { return "ecl-form-group"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-form-group-ec.css"],
            "eu": ["./build/styles/ecl-form-group-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-form-group-ec.css"],
            "eu": ["build/styles/ecl-form-group-eu.css"]
        };
    }
    static get properties() {
        return {
            "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",
                "defaultValue": "''"
            },
            "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"
            },
            "label": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "label"
            },
            "invalid": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "invalid",
                "defaultValue": "false"
            },
            "required": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "required",
                "defaultValue": "false"
            },
            "requiredText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "required-text",
                "defaultValue": "'*'"
            },
            "optionalText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "optional-text"
            },
            "invalidText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "invalid-text"
            },
            "helperText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "helper-text"
            },
            "helperId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "helper-id"
            },
            "hideLabel": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "hide-label",
                "defaultValue": "false"
            },
            "labelTag": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "label-tag",
                "defaultValue": "'label'"
            },
            "tag": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "tag",
                "defaultValue": "'div'"
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "name"
            },
            "invalidIcon": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "invalid-icon",
                "defaultValue": "'error'"
            },
            "labelClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "label-class"
            },
            "ariaLabelOptional": {
                "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-optional"
            },
            "ariaLabelRequired": {
                "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-required"
            }
        };
    }
    static get elementRef() { return "el"; }
}
