import { h } from "@stencil/core";
import { ElementQuestionBase } from '../../../utils/element-question-base';
export class BceElementInputTemplate {
    constructor() {
        // private handleInput(name: string, event: Event) {
        //   const input = event.target as any;
        //   if (!input) return;
        //
        //   const { value } = input;
        //   if (name === 'answer' && !value) this.hasAnswer = false;
        //   if (name === 'hasAnswer' && !value) this.answer = '';
        //   if (name === 'multiline') {
        //     this.hasAnswer = false;
        //     this.answer = '';
        //   }
        //
        //   event.cancelBubble = true;
        //   (this as any)[name] = value;
        //   this.value = this.updateValue({ [name]: value });
        //   this.el.dispatchEvent(new Event('input', { bubbles: true }));
        // }
        this.onAnswer = (value) => {
            if (!value)
                this.handler.set('hasAnswer', false);
        };
        this.onHasAnswer = (value) => {
            if (!value)
                this.handler.set('answer', '', { localize: true });
        };
        this.onMultiline = (value) => {
            this.handler.set('hasAnswer', false);
            this.handler.set('answer', '', { localize: true });
        };
    }
    prop(path, options = {}) {
        return this.handler.prop(path, Object.assign({}, options));
    }
    render() {
        const { hasAnswer, multiline } = this.value;
        return (h(ElementQuestionBase, { t: this.t, question: this.prop('question', { localize: true }), required: this.prop('required') },
            h("bce-switch", Object.assign({}, this.prop('multiline', { on: this.onMultiline }), { label: this.t('me-element-input-multiline') })),
            h("bce-input", Object.assign({}, this.prop('min'), { label: this.t('min'), type: "number" })),
            h("bce-input", Object.assign({}, this.prop('max'), { label: this.t('max'), type: "number" })),
            h("bce-switch", Object.assign({}, this.prop('hasAnswer', { on: this.onHasAnswer }), { label: this.t('answer') })),
            hasAnswer && (h("bce-input", Object.assign({}, this.prop('answer', { on: this.onAnswer, localize: true }), { type: multiline ? 'textarea' : 'text', validation: "required" }))),
            h("slot", null)));
    }
    static get is() { return "bce-element-input-editor"; }
    static get encapsulation() { return "shadow"; }
    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
        },
        "t": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "I18n.Translator",
                "resolved": "Translator<\"false\" | \"true\" | \"add-item\" | \"answer\" | \"category\" | \"column\" | \"delete-item\" | \"description\" | \"example\" | \"hide-item\" | \"icon\" | \"image\" | \"link\" | \"max\" | \"me-auto-play\" | \"me-block-subtitle\" | \"me-block-title\" | \"me-element-audio\" | \"me-element-checkbox-max\" | \"me-element-checkbox\" | \"me-element-download-placeholder\" | \"me-element-download\" | \"me-element-header-placeholder\" | \"me-element-header\" | \"me-element-icon\" | \"me-element-image\" | \"me-element-input-multiline\" | \"me-element-input\" | \"me-element-link\" | \"me-element-matrix\" | \"me-element-radio\" | \"me-element-slider\" | \"me-element-sort\" | \"me-element-table\" | \"me-element-text\" | \"me-element-video\" | \"me-module-advanced-options\" | \"me-module-graph-subtitle\" | \"me-module-graph-title\" | \"me-module-subtitle\" | \"me-module-title\" | \"me-option\" | \"me-orientation-h\" | \"me-orientation-v\" | \"me-orientation\" | \"me-other\" | \"me-question\" | \"me-required\" | \"min\" | \"name\" | \"row\" | \"show-item\" | \"step-size\" | \"text-left\" | \"text-right\" | \"text\" | \"upload-item\">",
                "references": {
                    "I18n": {
                        "location": "import",
                        "path": "@bce-technology/i18n"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "value": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "InputElement",
                "resolved": "InputElement",
                "references": {
                    "InputElement": {
                        "location": "import",
                        "path": "./element-input"
                    }
                }
            },
            "required": true,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            }
        }
    }; }
}
