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';

const BceElementInputTemplate = class {
    constructor(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');
    }
    handleInput(name, event) {
        const input = event.target;
        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[name] = value;
        this.value = this.updateValue({ [name]: value });
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    updateValue(part = {}) {
        const 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);
    }
    componentDidLoad() {
        this.value = this.updateValue();
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    render() {
        const { multiline } = this;
        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)))));
    }
    get el() { return getElement(this); }
};

export { BceElementInputTemplate as bce_element_input_template };
