import { h } from "@stencil/core";
export class BceElementInput {
    constructor() {
        this.handleInput = (event) => {
            event.cancelBubble = true;
            const target = event.target;
            this.value = target.value || '';
            this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
    }
    async validate(silent = false) {
        const input = this.el.shadowRoot.querySelector('bce-input');
        return input.validate(silent);
    }
    render() {
        const type = this.template.multiline ? 'textarea' : 'text';
        const validation = [
            this.template.min && 'min:' + this.template.min,
            this.template.max && 'max:' + this.template.max,
            this.template.required ? 'required' : null
        ]
            .filter(value => !!value)
            .join('|');
        return [
            h("p", null, this.handler.t('question')),
            h("bce-input", { value: this.value, onInput: this.handleInput, validation: validation, type: type })
        ];
    }
    static get is() { return "bce-element-input"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() { return {
        "$": ["bce-element-input.scss"]
    }; }
    static get styleUrls() { return {
        "$": ["bce-element-input.css"]
    }; }
    static get properties() { return {
        "handler": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "InputHandler",
                "resolved": "InputHandler",
                "references": {
                    "InputHandler": {
                        "location": "import",
                        "path": "../../../utils/input-handler"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "language": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string | undefined",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "language",
            "reflect": false
        },
        "template": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "InputElement",
                "resolved": "InputElement",
                "references": {
                    "InputElement": {
                        "location": "import",
                        "path": "./element-input"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "value": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "value",
            "reflect": false
        }
    }; }
    static get methods() { return {
        "validate": {
            "complexType": {
                "signature": "(silent?: boolean) => Promise<import(\"/Users/ngfk/Repositories/bce-module-editor/node_modules/@bcase/core/dist/types/index\").ValidatorError[]>",
                "parameters": [{
                        "tags": [],
                        "text": ""
                    }],
                "references": {
                    "Promise": {
                        "location": "global"
                    },
                    "ValidatorError": {
                        "location": "global"
                    }
                },
                "return": "Promise<ValidatorError[]>"
            },
            "docs": {
                "text": "",
                "tags": []
            }
        }
    }; }
    static get elementRef() { return "el"; }
}
