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 BceElementSortTemplate {
    constructor() {
        this.metadata = {};
        this.optionIcon = Block.ICON_MAP['sort'];
        this.question = '';
        this.required = false;
        this.dual = false;
        this.options = [];
        this.feedbackCorrect = '';
        this.feedbackIncorrect = '';
        this.labelQuestion = 'Formulate your question';
        this.labelRequired = 'Required';
        this.labelOCAddButton = 'Add';
        this.labelOCRemoveButton = 'Delete';
        this.labelOCOther = 'Other';
        this.labelOCImage = 'Image';
        this.labelDual = 'Dual';
        this.labelFeedbackCorrect = 'Feedback correct';
        this.labelFeedbackIncorrect = 'Feedback incorrect';
        this.placeholderOptions = 'Option';
        this.placeholderFeedbackCorrect = 'Feedback on correct answer';
        this.placeholderFeedbackIncorrect = 'Feedback on incorrect answer';
        this._link = linker(this, this.handleInput);
        this._question = this._link('question');
        this._required = this._link('required');
        this._dual = this._link('dual');
        this._options = this._link('options');
        this._feedbackCorrect = this._link('feedbackCorrect');
        this._feedbackIncorrect = this._link('feedbackIncorrect');
    }
    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,
            dual: this.dual,
            options: this.options,
            feedbackCorrect: this.feedbackCorrect,
            feedbackIncorrect: this.feedbackIncorrect,
            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 }, this._options);
        return (h(ElementQuestionBase, { question: this._question, required: this._required },
            h("bce-option-creator", Object.assign({}, options)),
            h("bce-input", Object.assign({ type: "switch" }, this._dual)),
            h("bce-input", Object.assign({ type: "textarea" }, this._feedbackCorrect)),
            h("bce-input", Object.assign({ type: "textarea" }, this._feedbackIncorrect))));
    }
    static get is() { return "bce-element-sort-template"; }
    static get properties() { return {
        "value": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "SortTemplate",
                "resolved": "undefined | { readonly metadata: ElementMetadata; readonly question: string; readonly required: boolean; readonly options: SortElementOption[]; readonly dual: boolean; readonly feedbackCorrect: string; readonly feedbackIncorrect: string; }",
                "references": {
                    "SortTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "metadata": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "Block.ElementMetadata",
                "resolved": "ElementMetadata",
                "references": {
                    "Block": {
                        "location": "import",
                        "path": "../../../models/block"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "{}"
        },
        "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['sort']"
        },
        "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"
        },
        "dual": {
            "type": "boolean",
            "mutable": true,
            "complexType": {
                "original": "boolean",
                "resolved": "boolean",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "dual",
            "reflect": false,
            "defaultValue": "false"
        },
        "options": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "SortTemplate['options']",
                "resolved": "SortElementOption[]",
                "references": {
                    "SortTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "[]"
        },
        "feedbackCorrect": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "feedback-correct",
            "reflect": false,
            "defaultValue": "''"
        },
        "feedbackIncorrect": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "feedback-incorrect",
            "reflect": false,
            "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'"
        },
        "labelDual": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-dual",
            "reflect": false,
            "defaultValue": "'Dual'"
        },
        "labelFeedbackCorrect": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-feedback-correct",
            "reflect": false,
            "defaultValue": "'Feedback correct'"
        },
        "labelFeedbackIncorrect": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-feedback-incorrect",
            "reflect": false,
            "defaultValue": "'Feedback incorrect'"
        },
        "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'"
        },
        "placeholderFeedbackCorrect": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-feedback-correct",
            "reflect": false,
            "defaultValue": "'Feedback on correct answer'"
        },
        "placeholderFeedbackIncorrect": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-feedback-incorrect",
            "reflect": false,
            "defaultValue": "'Feedback on incorrect answer'"
        }
    }; }
    static get elementRef() { return "el"; }
}
