var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { bindable, containerless, customElement, DOM, inlineView } from "aurelia-framework";
import { UIInternal } from "../../utils/ui-internal";
export var UITag = (function () {
    function UITag(element) {
        this.element = element;
        this.id = "";
        this.label = "";
        this.icon = "";
        this.href = null;
        this.onClick = null;
        this.size = "nm";
        this.type = "normal";
        this.textColor = null;
        this.backgroundColor = null;
        this.closeable = false;
        this.clickable = false;
        this.classes = "";
        this.style = "normal";
        this.styleObject = null;
        this.uiTheme = null;
    }
    UITag.prototype.backgroundColorChanged = function () {
        this.resetColors();
    };
    UITag.prototype.textColorChanged = function () {
        this.resetColors();
    };
    UITag.prototype.close = function () {
        var _this = this;
        if (this.beforeCloseFn) {
            this.beforeCloseFn();
        }
        UIInternal.fireCallbackEvent(this, "beforeclose", this.id).then(function (b) {
            return b ? _this.remove() : undefined;
        });
    };
    UITag.prototype.bind = function () {
        this.closeable = !isFalse(this.closeable);
        this.clickable = !isFalse(this.clickable) || this.href != null || this.onClick != null;
        this.resetColors();
    };
    UITag.prototype.remove = function () {
        var _this = this;
        this.element.dispatchEvent(UIInternal.createEvent("close", this.id));
        UIInternal.queueTask(function () {
            if (_this.vmElement) {
                DOM === null || DOM === void 0 ? void 0 : DOM.removeNode(_this.vmElement);
            }
        });
    };
    UITag.prototype.resetColors = function () {
        this.uiTheme = null;
        this.styleObject = {};
        if (this.backgroundColor != null) {
            if (this.backgroundColor.startsWith('ui-theme--')) {
                this.uiTheme = this.backgroundColor;
            }
            else {
                this.styleObject['background-color'] = this.backgroundColor;
            }
        }
        if (this.textColor != null && this.uiTheme == null) {
            this.styleObject['color'] = this.textColor;
        }
    };
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "id", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "label", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "icon", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "href", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Function)
    ], UITag.prototype, "onClick", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "size", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "type", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Function)
    ], UITag.prototype, "beforeCloseFn", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "textColor", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "backgroundColor", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Boolean)
    ], UITag.prototype, "closeable", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Boolean)
    ], UITag.prototype, "clickable", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UITag.prototype, "classes", void 0);
    UITag = __decorate([
        containerless(),
        customElement("ui-tag"),
        inlineView("<template>\n    <a class=\"ui-tag ui-tag--${type} ui-tag--${size} ${uiTheme} ${classes}\" class.bind=\"clickable ? '' : 'ui-tag-readonly'\" style.bind=\"styleObject\"\n     href.bind=\"href\" ref=\"vmElement\" click.delegate=\"onClick()\">\n      <div class=\"ui-tag__label\" title=\"${label}\">${label}</div>\n      <div class=\"ui-tag__icon\"><slot name=\"avatar\"><ui-icon if.bind=\"icon\" icon.bind=\"icon\"></ui-icon></slot></div>\n      <div class=\"ui-tag__value\"><slot></slot></div>\n      <div class=\"ui-tag__close\" if.bind=\"closeable\" click.trigger=\"[$event.stopEvent(), close()]\">\n        <ui-icon icon=\"digi-cross\"></ui-icon>\n      </div>\n    </a>\n  </template>"),
        __metadata("design:paramtypes", [Element])
    ], UITag);
    return UITag;
}());

//# sourceMappingURL=ui-tag.js.map
