import { r as registerInstance, h, g as getElement } from './core-095fd691.js';
import { B as Block } from './block-89b88b6d.js';
import { l as linker } from './input-linker-2b74e80e.js';
import { E as ElementQuestionBase } from './element-question-base-4a75829e.js';

const BceElementCheckboxTemplate = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.metadata = {};
        this.optionIcon = Block.ICON_MAP['checkbox'];
        this.question = '';
        this.required = false;
        this.options = [];
        this.other = false;
        this.orientation = 'vertical';
        this.answer = [];
        this.labelQuestion = 'Formulate your question';
        this.labelRequired = 'Required';
        this.labelMax = 'Max antwoorden';
        this.labelOCAddButton = 'Add';
        this.labelOCRemoveButton = 'Delete';
        this.labelOCOther = 'Other';
        this.labelOCImage = 'Image';
        this.labelOrientation = 'Oriëntation';
        this.labelOrientationH = 'Horizontal';
        this.labelOrientationV = 'Vertical';
        this.placeholderOptions = 'Option';
        this._link = linker(this, this.handleInput);
        this._question = this._link('question');
        this._required = this._link('required');
        this._options = this._link('options');
        // private _answer = this._link('answer');
        this._orientation = this._link('orientation');
        this.handleMax = (event) => {
            const input = event.target;
            if (!input)
                return;
            const value = input.value ? input.value + '' : '';
            event.cancelBubble = true;
            this.validation = value ? 'max:' + value : '';
            this.value = this.updateValue({ validation: this.validation });
            this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
        this.handleOther = (event) => {
            const input = event.target;
            if (!input)
                return;
            this.other = event.detail;
            this.value = this.updateValue({
                options: input.value,
                other: event.detail
            });
            this.el.dispatchEvent(new Event('input', { bubbles: true }));
        };
    }
    handleInput(name, event) {
        const input = event.target;
        if (!input)
            return;
        event.cancelBubble = true;
        this[name] = input.value;
        this.value = this.updateValue({ [name]: input.value });
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    updateValue(part = {}) {
        const current = {
            question: this.question,
            required: this.required,
            validation: this.validation,
            options: this.options,
            other: this.other,
            orientation: this.orientation,
            answer: this.answer,
            metadata: Object.assign({}, this.metadata)
        };
        return Object.assign({}, current, part);
    }
    componentDidLoad() {
        this.value = this.updateValue();
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    render() {
        const options = Object.assign({ icon: this.optionIcon, labelOCAddButton: this.labelOCAddButton, labelOCRemoveButton: this.labelOCRemoveButton, labelOCOther: this.labelOCOther, labelOCImage: this.labelOCImage, other: this.other, onOther: this.handleOther, allowOther: true }, this._options);
        const maxValue = this.validation
            ? parseInt(this.validation.slice(4))
            : undefined;
        return (h(ElementQuestionBase, { question: this._question, required: this._required }, h("bce-option-creator", Object.assign({}, options)), h("bce-input", { type: "number", label: this.labelMax, value: maxValue, onInput: this.handleMax, numberMin: "1", numberMax: this.options ? this.options.length + '' : '' }), h("bce-input", Object.assign({ type: "radio", value: this.orientation }, this._orientation), h("bce-option", { value: "horizontal" }, this.labelOrientationH), h("bce-option", { value: "vertical" }, this.labelOrientationV)), h("slot", null)));
    }
    get el() { return getElement(this); }
};

export { BceElementCheckboxTemplate as bce_element_checkbox_template };
