'use strict';

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

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

const BceElementSmileyTemplate = class {
    constructor(hostRef) {
        core.registerInstance(this, hostRef);
        this.metadata = {};
        this.optionIcon = block.Block.ICON_MAP['icon'];
        this.question = '';
        this.required = false;
        this.options = [
            { text: 'fas:sad-tear', color: '#ef8b54' },
            { text: 'fas:frown-open', color: '#f3ac4c' },
            { text: 'fas:meh', color: '#f6d24c' },
            { text: 'fas:grin', color: '#d7f18e' },
            { text: 'fas:laugh', color: '#aad77e' }
        ];
        this.labelQuestion = 'Formulate your question';
        this.labelRequired = 'Required';
        this.labelOCAddButton = 'Add';
        this.labelOCRemoveButton = 'Delete';
        this.labelOCOther = 'Other';
        this.labelOCImage = 'Image';
        this.placeholderOptions = 'Icon';
        this._link = inputLinker.linker(this, this.handleInput);
        this._question = this._link('question');
        this._required = this._link('required');
        this._options = this._link('options');
    }
    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,
            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.options.map(o => o.text || this.optionIcon), labelOCAddButton: this.labelOCAddButton, labelOCRemoveButton: this.labelOCRemoveButton, labelOCOther: this.labelOCOther, labelOCImage: this.labelOCImage, allowImage: false, allowColor: true }, this._options);
        return (core.h(elementQuestionBase.ElementQuestionBase, { question: this._question, required: this._required }, core.h("bce-option-creator", Object.assign({}, options))));
    }
    get el() { return core.getElement(this); }
};

exports.bce_element_icon_template = BceElementSmileyTemplate;
