import { h } from "@stencil/core";
export class EclInput {
    constructor() {
        this.theme = 'ec';
        this.styleClass = undefined;
        this.inputClass = undefined;
        this.eclScript = false;
        this.disabled = false;
        this.required = false;
        this.invalid = false;
        this.helperText = undefined;
        this.placeholder = undefined;
        this.width = 'm';
        this.label = undefined;
        this.type = undefined;
        this.inputId = undefined;
        this.name = undefined;
        this.defaultValue = undefined;
        this.value = undefined;
        this.hasChanged = false;
        this.isFocused = false;
    }
    componentDidRender() {
        if (this.inputId) {
            const group = this.el.closest('.ecl-form-group');
            if (group) {
                const label = group.querySelector('.ecl-form-label');
                if (label) {
                    if (this.type !== 'radio' && this.type !== 'checkbox') {
                        label.setAttribute('for', this.inputId);
                    }
                    label.setAttribute('id', `${this.inputId}-label`);
                }
                const helper = group.querySelector('.ecl-help-block');
                if (helper) {
                    if (this.type !== 'radio' && this.type !== 'checkbox') {
                        helper.setAttribute('id', `${this.inputId}-helper`);
                    }
                }
            }
        }
    }
    getClass() {
        const styleClasses = ['ecl-input', this.styleClass];
        if (this.type === 'checkbox') {
            styleClasses.push('ecl-checkbox', `ecl-checkbox--${this.width}`);
            if (this.disabled) {
                styleClasses.push('ecl-checkbox--disabled');
            }
            if (this.invalid) {
                styleClasses.push('ecl-checkbox--invalid');
            }
        }
        if (this.type === 'radio') {
            styleClasses.push('ecl-radio', `ecl-radio--${this.width}`);
            if (this.disabled) {
                styleClasses.push('ecl-radio--disabled');
            }
            if (this.invalid) {
                styleClasses.push('ecl-radio--invalid');
            }
        }
        return styleClasses.join(' ');
    }
    getInputClasses(input) {
        let inputClasses = [`ecl-${input}__input`];
        if (this.type === 'text' || this.type === 'search') {
            inputClasses = ['ecl-text-input', `ecl-text-input--${this.width}`];
            if (this.invalid) {
                inputClasses.push('ecl-text-input--invalid');
            }
            if (this.disabled) {
                inputClasses.push('ecl-text-input--disabled');
            }
        }
        if (this.inputClass) {
            inputClasses.push(this.inputClass);
        }
        return inputClasses.join(' ');
    }
    getBoxClasses(input, box) {
        let boxClasses = [`ecl-${input}__${box}`];
        if (this.disabled) {
            boxClasses.push(`ecl-${input}__${box}--disabled`);
        }
        if (this.invalid) {
            boxClasses.push(`ecl-${input}__${box}--invalid`);
        }
        return boxClasses.join(' ');
    }
    handleInput(event) {
        this.value = event.target.value;
    }
    handleFocus(event) {
        this.inputFocus.emit(event);
        this.isFocused = true;
    }
    handleChange(event) {
        const value = event.target.value;
        this.inputChange.emit({ type: this.type, value });
    }
    handleBlur(event) {
        this.inputBlur.emit(event);
        this.isFocused = false;
    }
    render() {
        const wrapperAttrs = {};
        const attributes = {
            class: this.getInputClasses(this.type),
            type: this.type,
            id: this.inputId,
            name: this.name,
            required: this.required,
            disabled: this.disabled,
            value: this.defaultValue,
            placeholder: this.placeholder,
        };
        return (h("div", Object.assign({ class: this.getClass() }, wrapperAttrs), h("input", Object.assign({}, attributes, { onInput: ev => this.handleInput(ev), onFocus: ev => this.handleFocus(ev), onBlur: ev => this.handleBlur(ev), onChange: ev => this.handleChange(ev) })), this.type === 'checkbox' ?
            h("label", { class: this.getBoxClasses('checkbox', 'label'), htmlFor: this.inputId }, h("span", { class: this.getBoxClasses('checkbox', 'box') }, h("ecl-icon", { "style-class": `ecl-checkbox__icon sc-ecl-input-${this.theme}`, icon: "check", size: "m" })), h("span", { class: "ecl-checkbox__text" }, this.label))
            : '', this.type === 'checkbox' && this.helperText ?
            h("div", Object.assign({ class: "ecl-checkbox__help" }, (this.inputId ? { 'id': `${this.inputId}-helper` } : {})), this.helperText)
            : '', this.type === 'radio' ?
            h("label", { class: this.getBoxClasses('radio', 'label'), htmlFor: this.inputId }, h("span", { class: this.getBoxClasses('radio', 'box') }, h("span", { class: "ecl-radio__box-inner" })), h("span", { class: "ecl-radio__text" }, this.label))
            : '', this.type === 'radio' && this.helperText ?
            h("div", Object.assign({ class: "ecl-radio__help" }, (this.inputId ? { 'id': `${this.inputId}-helper` } : {})), this.helperText)
            : ''));
    }
    static get is() { return "ecl-input"; }
    static get encapsulation() { return "scoped"; }
    static get originalStyleUrls() {
        return {
            "ec": ["./build/styles/ecl-input-ec.css"],
            "eu": ["./build/styles/ecl-input-eu.css"]
        };
    }
    static get styleUrls() {
        return {
            "ec": ["build/styles/ecl-input-ec.css"],
            "eu": ["build/styles/ecl-input-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
            },
            "inputClass": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "input-class",
                "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"
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "disabled",
                "reflect": false,
                "defaultValue": "false"
            },
            "required": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "required",
                "reflect": false,
                "defaultValue": "false"
            },
            "invalid": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "invalid",
                "reflect": false,
                "defaultValue": "false"
            },
            "helperText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "helper-text",
                "reflect": false
            },
            "placeholder": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "placeholder",
                "reflect": false
            },
            "width": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "width",
                "reflect": false,
                "defaultValue": "'m'"
            },
            "label": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "label",
                "reflect": false
            },
            "type": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "type",
                "reflect": false
            },
            "inputId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "input-id",
                "reflect": false
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "name",
                "reflect": false
            },
            "defaultValue": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "default-value",
                "reflect": false
            },
            "hasChanged": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "has-changed",
                "reflect": false,
                "defaultValue": "false"
            },
            "isFocused": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "is-focused",
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "value": {}
        };
    }
    static get events() {
        return [{
                "method": "inputFocus",
                "name": "inputFocus",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "FocusEvent",
                    "resolved": "FocusEvent",
                    "references": {
                        "FocusEvent": {
                            "location": "global",
                            "id": "global::FocusEvent"
                        }
                    }
                }
            }, {
                "method": "inputBlur",
                "name": "inputBlur",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "FocusEvent",
                    "resolved": "FocusEvent",
                    "references": {
                        "FocusEvent": {
                            "location": "global",
                            "id": "global::FocusEvent"
                        }
                    }
                }
            }, {
                "method": "inputChange",
                "name": "inputChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "{ type: string; value: string }",
                    "resolved": "{ type: string; value: string; }",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-input.js.map
