import { r as registerInstance, h, g as getElement } from './core-095fd691.js';
import { l as linker } from './input-linker-2b74e80e.js';
import { E as ElementQuestionBase } from './element-question-base-5de5ce16.js';
var BceElementInputTemplate = /** @class */ (function () {
    function class_1(hostRef) {
        registerInstance(this, hostRef);
        this.question = '';
        this.required = false;
        this.multiline = false;
        this.min = null;
        this.max = null;
        this.answer = '';
        this.hasAnswer = !!this.answer;
        this.labelQuestion = 'Formulate your question';
        this.labelRequired = 'Required';
        this.labelMultiline = 'Multiline';
        this.labelMin = 'Min';
        this.labelMax = 'Max';
        this.labelHasAnswer = 'Answer';
        this.labelAnswer = '';
        this.placeholderAnswer = 'Formulate the correct answer';
        this._link = linker(this, this.handleInput);
        this._question = this._link('question');
        this._required = this._link('required');
        this._multiline = this._link('multiline');
        this._min = this._link('min');
        this._max = this._link('max');
        this._answer = this._link('answer');
        this._hasAnswer = this._link('hasAnswer');
    }
    class_1.prototype.handleInput = function (name, event) {
        var _a;
        var input = event.target;
        if (!input)
            return;
        var value = input.value;
        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[name] = value;
        this.value = this.updateValue((_a = {}, _a[name] = value, _a));
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    };
    class_1.prototype.updateValue = function (part) {
        if (part === void 0) { part = {}; }
        var current = {
            question: this.question,
            required: this.required,
            multiline: this.multiline,
            min: this.min,
            max: this.max,
            answer: this.answer,
            hasAnswer: this.hasAnswer
        };
        return Object.assign({}, current, part);
    };
    class_1.prototype.componentDidLoad = function () {
        this.value = this.updateValue();
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    };
    class_1.prototype.render = function () {
        var multiline = this.multiline;
        return (h(ElementQuestionBase, { question: this._question, required: this._required }, h("bce-input", Object.assign({ type: "switch" }, this._multiline)), h("bce-input", Object.assign({ type: "number" }, this._min)), h("bce-input", Object.assign({ type: "number" }, this._max)), h("bce-input", Object.assign({ type: "switch" }, this._hasAnswer)), this.hasAnswer && (h("bce-input", Object.assign({ type: multiline ? 'textarea' : 'text' }, this._answer)))));
    };
    Object.defineProperty(class_1.prototype, "el", {
        get: function () { return getElement(this); },
        enumerable: true,
        configurable: true
    });
    return class_1;
}());
export { BceElementInputTemplate as bce_element_input_template };
