'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index$1 = require('./index-578e90b1.js');
const elementQuestionBase = require('./element-question-base-0c6e17d9.js');

const BceElementInputTemplate = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        // 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 (index$1.h(elementQuestionBase.ElementQuestionBase, { t: this.t, question: this.prop('question', { localize: true }), required: this.prop('required') }, index$1.h("bce-switch", Object.assign({}, this.prop('multiline', { on: this.onMultiline }), { label: this.t('me-element-input-multiline') })), index$1.h("bce-input", Object.assign({}, this.prop('min'), { label: this.t('min'), type: "number" })), index$1.h("bce-input", Object.assign({}, this.prop('max'), { label: this.t('max'), type: "number" })), index$1.h("bce-switch", Object.assign({}, this.prop('hasAnswer', { on: this.onHasAnswer }), { label: this.t('answer') })), hasAnswer && (index$1.h("bce-input", Object.assign({}, this.prop('answer', { on: this.onAnswer, localize: true }), { type: multiline ? 'textarea' : 'text', validation: "required" }))), index$1.h("slot", null)));
    }
};

exports.bce_element_input_editor = BceElementInputTemplate;
