'use strict';

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

const core = require('./core-0f211bec.js');
const block = require('./block-eafe6439.js');
const inputLinker = require('./input-linker-dc14a9fc.js');
const elementQuestionBase = require('./element-question-base-45352939.js');

const BceElementRadioTemplate = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.optionIcon = block.Block.ICON_MAP[block.Block.Type.Radio];
        this.question = '';
        this.required = false;
        this.options = [];
        this.other = false;
        this.orientation = 'vertical';
        this.answer = null;
        this.labelQuestion = 'Formulate your question';
        this.labelRequired = 'Required';
        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 = inputLinker.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.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,
            options: this.options,
            other: this.other,
            orientation: this.orientation,
            answer: this.answer
        };
        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);
        return (core.h(elementQuestionBase.ElementQuestionBase, { question: this._question, required: this._required }, core.h("bce-option-creator", Object.assign({}, options)), core.h("bce-input", Object.assign({ type: "radio" }, this._orientation), core.h("bce-option", { value: "horizontal" }, this.labelOrientationH), core.h("bce-option", { value: "vertical" }, this.labelOrientationV))));
    }
    get el() { return core.getElement(this); }
};

exports.bce_element_radio_template = BceElementRadioTemplate;
