"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UIButtonGroup = void 0;
var aurelia_framework_1 = require("aurelia-framework");
var ui_internal_1 = require("../../utils/ui-internal");
var ui_button_1 = require("./ui-button");
var UIButtonGroup = exports.UIButtonGroup = (function () {
    function UIButtonGroup(element) {
        this.element = element;
        this.value = "";
        this.separator = "";
        this.size = "nm";
        this.type = "default";
        this.disabled = false;
        this.toggle = false;
        this.elDisabled = false;
        if (element.hasAttribute("equal")) {
            element.classList.add("ui-btn__group--equal");
        }
        if (element.hasAttribute("vertical")) {
            element.classList.add("ui-btn__group--vertical");
        }
        this.toggle = element.hasAttribute("toggle");
    }
    Object.defineProperty(UIButtonGroup.prototype, "isDisabled", {
        get: function () {
            return this.disabled || this.elDisabled;
        },
        enumerable: false,
        configurable: true
    });
    UIButtonGroup.prototype.disable = function (disabled) {
        this.elDisabled = disabled;
    };
    UIButtonGroup.prototype.attached = function () {
        var _this = this;
        if (this.separator) {
            this.element.classList.add("ui-btn__group--with-separator");
        }
        if (this.toggle) {
            ui_internal_1.UIInternal.queueTask(function () { return _this.valueChanged(_this.value, ""); });
        }
    };
    UIButtonGroup.prototype.buttonsChanged = function () {
        var _this = this;
        this.buttons.forEach(function (b) {
            b.element.dataset.separator = _this.separator;
        });
    };
    UIButtonGroup.prototype.valueChanged = function (newValue, oldValue) {
        if (this.buttons) {
            var btn = this.buttons.find(function (b) { return b.id === newValue; });
            if (btn) {
                if (this.currentSelected) {
                    this.currentSelected.active = false;
                }
                (this.currentSelected = btn).active = true;
            }
            else {
                this.value = oldValue;
            }
        }
    };
    UIButtonGroup.prototype.buttonClicked = function ($event) {
        $event.stopEvent();
        if ($event.detail && this.toggle) {
            this.value = $event.detail;
        }
    };
    __decorate([
        (0, aurelia_framework_1.bindable)({ bindingMode: aurelia_framework_1.bindingMode.twoWay }),
        __metadata("design:type", String)
    ], UIButtonGroup.prototype, "value", void 0);
    __decorate([
        (0, aurelia_framework_1.bindable)(),
        __metadata("design:type", String)
    ], UIButtonGroup.prototype, "separator", void 0);
    __decorate([
        (0, aurelia_framework_1.bindable)(),
        __metadata("design:type", String)
    ], UIButtonGroup.prototype, "size", void 0);
    __decorate([
        (0, aurelia_framework_1.bindable)(),
        __metadata("design:type", String)
    ], UIButtonGroup.prototype, "type", void 0);
    __decorate([
        (0, aurelia_framework_1.bindable)(),
        __metadata("design:type", Boolean)
    ], UIButtonGroup.prototype, "disabled", void 0);
    __decorate([
        (0, aurelia_framework_1.child)("ui-button[data-active='true']"),
        __metadata("design:type", ui_button_1.UIButton)
    ], UIButtonGroup.prototype, "currentSelected", void 0);
    __decorate([
        (0, aurelia_framework_1.children)("ui-button"),
        __metadata("design:type", Array)
    ], UIButtonGroup.prototype, "buttons", void 0);
    __decorate([
        (0, aurelia_framework_1.computedFrom)("disabled", "elDisabled"),
        __metadata("design:type", Boolean),
        __metadata("design:paramtypes", [])
    ], UIButtonGroup.prototype, "isDisabled", null);
    UIButtonGroup = __decorate([
        (0, aurelia_framework_1.autoinject)(),
        (0, aurelia_framework_1.customElement)("ui-button-group"),
        (0, aurelia_framework_1.inlineView)("<template class=\"ui-btn__group\" click.delegate=\"buttonClicked($event)\" data-disabled.bind=\"isDisabled\" data-size.bind=\"size\" data-type.bind=\"type\"><slot></slot></template>"),
        __metadata("design:paramtypes", [Element])
    ], UIButtonGroup);
    return UIButtonGroup;
}());

//# sourceMappingURL=ui-button-group.js.map
