import { h } from "@stencil/core";
import { Block } from '../../models/block';
import { ElementQuestionBase } from '../../utils/element-question-base';
import { linker } from '../../utils/input-linker';
export class BceElementCheckboxTemplate {
    constructor() {
        this.optionIcon = Block.ICON_MAP[Block.Type.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.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.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 (h(ElementQuestionBase, { question: this._question, required: this._required },
            h("bce-option-creator", Object.assign({}, options)),
            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))));
    }
    static get is() { return "bce-element-checkbox-template"; }
    static get properties() { return {
        "value": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "CheckboxTemplate",
                "resolved": "undefined | { readonly answer: number[]; readonly question: string; readonly required: boolean; readonly orientation: \"horizontal\" | \"vertical\"; readonly options: SelectElementOption[]; readonly other: boolean; }",
                "references": {
                    "CheckboxTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "optionIcon": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "option-icon",
            "reflect": false,
            "defaultValue": "Block.ICON_MAP[Block.Type.Checkbox]"
        },
        "question": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "question",
            "reflect": false,
            "defaultValue": "''"
        },
        "required": {
            "type": "boolean",
            "mutable": true,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "required",
            "reflect": false,
            "defaultValue": "false"
        },
        "options": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "never[]",
                "resolved": "never[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "[]"
        },
        "other": {
            "type": "boolean",
            "mutable": true,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "other",
            "reflect": false,
            "defaultValue": "false"
        },
        "orientation": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "CheckboxTemplate['orientation']",
                "resolved": "\"horizontal\" | \"vertical\"",
                "references": {
                    "CheckboxTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "orientation",
            "reflect": true,
            "defaultValue": "'vertical'"
        },
        "answer": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "never[]",
                "resolved": "never[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "[]"
        },
        "labelQuestion": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-question",
            "reflect": false,
            "defaultValue": "'Formulate your question'"
        },
        "labelRequired": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-required",
            "reflect": false,
            "defaultValue": "'Required'"
        },
        "labelOCAddButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-o-c-add-button",
            "reflect": false,
            "defaultValue": "'Add'"
        },
        "labelOCRemoveButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-o-c-remove-button",
            "reflect": false,
            "defaultValue": "'Delete'"
        },
        "labelOCOther": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-o-c-other",
            "reflect": false,
            "defaultValue": "'Other'"
        },
        "labelOCImage": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-o-c-image",
            "reflect": false,
            "defaultValue": "'Image'"
        },
        "labelOrientation": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-orientation",
            "reflect": false,
            "defaultValue": "'Ori\u00EBntation'"
        },
        "labelOrientationH": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-orientation-h",
            "reflect": false,
            "defaultValue": "'Horizontal'"
        },
        "labelOrientationV": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-orientation-v",
            "reflect": false,
            "defaultValue": "'Vertical'"
        },
        "placeholderOptions": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-options",
            "reflect": false,
            "defaultValue": "'Option'"
        }
    }; }
    static get elementRef() { return "el"; }
}
