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);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import { bindable, bindingMode, customElement, inlineView, processContent, viewResources } from "aurelia-framework";
import { UIInternal } from "../../utils/ui-internal";
import { MenuItem } from "./menu-item";
export var UIMenu = (function () {
    function UIMenu(element) {
        this.element = element;
        this.noitemsLabel = "No Menu";
        this.isLoading = false;
    }
    UIMenu.prototype.menuItemsChanged = function () {
        this.loadMenuItems();
    };
    UIMenu.prototype.attached = function () {
        var _this = this;
        UIInternal.queueTask(function () {
            var active = _this.element.querySelector(".ui-menu__item__link[data-active='true']");
            if (active) {
                active.scrollIntoView({ block: "center", inline: "nearest" });
            }
        });
    };
    UIMenu.prototype.loadMenuItems = function () {
        var _a;
        var _this = this;
        if (isFunction(this.menuItems)) {
            this.isLoading = true;
            var ret = this.menuItems();
            if (ret instanceof Promise) {
                ret.then(function (items) {
                    _this.items = items;
                    _this.isLoading = false;
                });
            }
            else {
                this.items = ret;
                this.isLoading = false;
            }
        }
        else if (isArray(this.menuItems)) {
            if (this.items != null) {
                this.items.splice(0);
            }
            else {
                this.items = [];
            }
            (_a = this.items).push.apply(_a, __spreadArray([], __read(this.menuItems), false));
        }
        else {
            this.items = undefined;
        }
    };
    __decorate([
        bindable(),
        __metadata("design:type", Object)
    ], UIMenu.prototype, "menuItems", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenu.prototype, "noitemsLabel", void 0);
    __decorate([
        bindable({ defaultBindingMode: bindingMode.toView }),
        __metadata("design:type", Array)
    ], UIMenu.prototype, "items", void 0);
    UIMenu = __decorate([
        customElement("ui-menu"),
        viewResources(MenuItem),
        inlineView("<template class=\"ui-menu\"><slot>\n  <div if.bind=\"isLoading\" ui-padding=\"xs\" ui-align=\"center\"><ui-svg-icon icon=\"busy\" class=\"ui-anim--spin\"></ui-svg-icon></div>\n  <template if.bind=\"!isLoading && items && items.length\">\n    <menu-item repeat.for=\"item of items\" item.bind=\"item\" noitems-label.bind=\"noitemsLabel\"></menu-item>\n  </template>\n  <template if.bind=\"!isLoading && items && items.length===0\">\n    <div ui-padding=\"xs\" ui-color=\"muted\" ui-font=\"sm\" innerhtml.bind=\"noitemsLabel\"></div>\n  </template>\n</slot></template>"),
        processContent(function (compiler, resources, node, instruction) {
            instruction.inheritBindingContext = true;
            return true;
        }),
        __metadata("design:paramtypes", [Element])
    ], UIMenu);
    return UIMenu;
}());

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