import { Host, h } from "@stencil/core";
import isNil from "lodash.isnil";
import { BEM } from "../../../utils/bem";
import { stopEventBubbling } from "../../../utils/form-input";
export class DataValue {
    constructor() {
        /**
         * If `true` a small button with a edit icon will be shown on the right.
         */
        this.editable = false;
        /**
         * If `true` the button will get disabled.
         */
        this.disabled = false;
        /**
         * If `true` the text will break and the height of the item increases.
         */
        this.multiline = false;
        this.onClickHandler = (ev) => {
            const input = this.el.querySelector('bal-input');
            if (!isNil(input)) {
                input.setFocus();
            }
            stopEventBubbling(ev);
            this.balClick.emit(ev.detail);
        };
    }
    render() {
        const block = BEM.block('data-value');
        const buttonEl = block.element('button');
        return (h(Host, { key: '1407b2c714f532e06ffcba50e1c21a06d33f34fe', class: Object.assign(Object.assign(Object.assign({}, block.class()), block.modifier('is-editable').class(this.editable)), block.modifier('is-multiline').class(this.multiline)) }, h("div", { key: '71427202ef765e83e32b631eb277b9432b80c8c3' }, h("slot", { key: '0bbe71b9ebe87bc23941aab4f9643f5d58ea31c6' })), h("bal-button", { key: '5ba17c254646c82d8e6d8d9c8e5a229326542b12', class: Object.assign({}, buttonEl.class()), "data-testid": "bal-data-value-button", square: true, outlined: true, color: "text", size: "small", icon: "edit", disabled: this.disabled, onBalBlur: _ => this.balBlur.emit(), onBalFocus: _ => this.balFocus.emit(), onBalClick: ev => this.onClickHandler(ev) })));
    }
    static get is() { return "bal-data-value"; }
    static get properties() {
        return {
            "editable": {
                "type": "boolean",
                "attribute": "editable",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` a small button with a edit icon will be shown on the right."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "disabled": {
                "type": "boolean",
                "attribute": "disabled",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the button will get disabled."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "multiline": {
                "type": "boolean",
                "attribute": "multiline",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If `true` the text will break and the height of the item increases."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            }
        };
    }
    static get events() {
        return [{
                "method": "balClick",
                "name": "balClick",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the edit button has focus."
                },
                "complexType": {
                    "original": "BalEvents.BalDataValueClickDetail",
                    "resolved": "MouseEvent",
                    "references": {
                        "BalEvents": {
                            "location": "global",
                            "id": "global::BalEvents"
                        }
                    }
                }
            }, {
                "method": "balFocus",
                "name": "balFocus",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the edit button has focus."
                },
                "complexType": {
                    "original": "BalEvents.BalDataValueFocusDetail",
                    "resolved": "void",
                    "references": {
                        "BalEvents": {
                            "location": "global",
                            "id": "global::BalEvents"
                        }
                    }
                }
            }, {
                "method": "balBlur",
                "name": "balBlur",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Emitted when the edit button loses focus."
                },
                "complexType": {
                    "original": "BalEvents.BalDataValueBlurDetail",
                    "resolved": "void",
                    "references": {
                        "BalEvents": {
                            "location": "global",
                            "id": "global::BalEvents"
                        }
                    }
                }
            }];
    }
    static get elementRef() { return "el"; }
}
