'use strict';

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

const index$1 = require('./index-457520a1.js');
const elementQuestionBase = require('./element-question-base-a6f39464.js');

const BceElementInputTemplate = class {
    constructor(hostRef) {
        index$1.registerInstance(this, hostRef);
        this.label = {
            name: 'Input',
            labelQuestion: 'Formulate your question',
            labelRequired: 'Required',
            labelMultiline: 'Multiline',
            labelMin: 'Min',
            labelMax: 'Max',
            labelHasAnswer: 'Answer',
            labelAnswer: '',
            placeholderAnswer: 'Formulate the correct answer'
        };
        // 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(Object.assign({}, options), { label: this.label }));
    }
    render() {
        const { hasAnswer, multiline } = this.value;
        return (index$1.h(elementQuestionBase.ElementQuestionBase, { question: this.prop('question', { localize: true }), required: this.prop('required') }, index$1.h("bce-switch", Object.assign({}, this.prop('multiline', { on: this.onMultiline }))), index$1.h("bce-input", Object.assign({}, this.prop('min'), { type: "number" })), index$1.h("bce-input", Object.assign({}, this.prop('max'), { type: "number" })), index$1.h("bce-switch", Object.assign({}, this.prop('hasAnswer', { on: this.onHasAnswer }))), 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;
