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 BceElementTableTemplate {
    constructor() {
        this.metadata = {};
        this.optionIcon = Block.ICON_MAP['table'];
        this.question = '';
        this.required = false;
        this.columns = [];
        this.orientation = 'horizontal';
        this.maxRows = 0;
        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.labelMaxRows = 'Max row count';
        this.placeholderColumns = 'Column';
        this._link = linker(this, this.handleInput);
        this._question = this._link('question');
        this._required = this._link('required');
        this._columns = this._link('columns');
        this._orientation = this._link('orientation');
        this._maxRows = this._link('maxRows');
    }
    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,
            columns: this.columns,
            orientation: this.orientation,
            maxRows: this.maxRows,
            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 columns = Object.assign({ icon: this.optionIcon, labelOCAddButton: this.labelOCAddButton, labelOCRemoveButton: this.labelOCRemoveButton, labelOCOther: this.labelOCOther, labelOCImage: this.labelOCImage }, this._columns);
        return (h(ElementQuestionBase, { question: this._question, required: this._required },
            h("bce-option-creator", Object.assign({}, columns)),
            h("bce-input", Object.assign({ type: "radio" }, this._orientation),
                h("bce-option", { value: "horizontal" }, this.labelOrientationH),
                h("bce-option", { value: "vertical" }, this.labelOrientationV)),
            h("bce-input", Object.assign({ type: "number" }, this._maxRows))));
    }
    static get is() { return "bce-element-table-template"; }
    static get properties() { return {
        "value": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "TableTemplate",
                "resolved": "undefined | { readonly metadata: ElementMetadata; readonly question: string; readonly required: boolean; readonly orientation: \"horizontal\" | \"vertical\"; readonly columns: TableElementColumn[]; readonly maxRows: number; }",
                "references": {
                    "TableTemplate": {
                        "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['table']"
        },
        "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"
        },
        "columns": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "never[]",
                "resolved": "never[]",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "[]"
        },
        "orientation": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "TableTemplate['orientation']",
                "resolved": "\"horizontal\" | \"vertical\"",
                "references": {
                    "TableTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "orientation",
            "reflect": false,
            "defaultValue": "'horizontal'"
        },
        "maxRows": {
            "type": "number",
            "mutable": true,
            "complexType": {
                "original": "number",
                "resolved": "number",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "max-rows",
            "reflect": false,
            "defaultValue": "0"
        },
        "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'"
        },
        "labelMaxRows": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-max-rows",
            "reflect": false,
            "defaultValue": "'Max row count'"
        },
        "placeholderColumns": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-columns",
            "reflect": false,
            "defaultValue": "'Column'"
        }
    }; }
    static get elementRef() { return "el"; }
}
