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 { Config } from '../../config';
import { bindable, child, computedFrom, Container, customElement } from 'aurelia-framework';
import { UIInternal } from '../../utils/ui-internal';
export var UIMenuItem = (function () {
    function UIMenuItem(element) {
        this.element = element;
        this.label = '';
        this.href = '';
        this.icon = '';
        this.iconColor = '';
        this.color = '';
        this.classes = '';
        this.active = false;
        this.disabled = false;
        this.dropIcon = 'caret';
        this.isInMenubar = false;
        this.hasDrop = false;
        this.split = element.hasAttribute('split');
        this.appConfig = Container.instance.get(Config);
    }
    Object.defineProperty(UIMenuItem.prototype, "uiColor", {
        get: function () {
            if (this.iconColor != null && this.iconColor.trim() != '') {
                return this.iconColor;
            }
            if (this.color != null && this.color.trim() != '') {
                return this.color;
            }
            return '';
        },
        enumerable: false,
        configurable: true
    });
    UIMenuItem.prototype.attached = function () {
        var _this = this;
        UIInternal.queueTask(function () {
            _this.hasDrop = !!_this.elDropdown;
            _this.isInMenubar = hasParent(_this.element, 'ui-menu__bar');
            var isInDropdown = hasParent(_this.element, 'ui-drop__body');
            if (_this.hasDrop) {
                _this.dropEl = getSlotViewModel(_this.elDropdown);
                if (isInDropdown || !_this.isInMenubar) {
                    _this.dropIcon = 'page-next';
                    _this.dropEl.position = 'tl';
                    _this.dropEl.anchorPosition = 'tr';
                    _this.dropEl.stretch = false;
                    _this.dropEl.attachToViewport = isInDropdown;
                }
                _this.dropEl.tether(_this.element);
            }
        });
        this.hrefChanged();
    };
    UIMenuItem.prototype.hrefChanged = function () {
        if (this.badgeEl) {
            if (this.href) {
                this.badgeEl.href = this.href;
            }
            else if (this.badgeEl.attributes.getNamedItem('href')) {
                this.badgeEl.attributes.removeNamedItem('href');
            }
        }
    };
    UIMenuItem.prototype.activeChanged = function () {
        if (this.active) {
            this.element.scrollIntoView({ block: 'center', inline: 'nearest' });
        }
    };
    UIMenuItem.prototype.fireClick = function ($event) {
        if (!this.href) {
            if (this.hasDrop && !this.split) {
                return this.toggleDrop();
            }
            return true;
        }
    };
    UIMenuItem.prototype.toggleDrop = function () {
        var beforeEvent = this.dropEl.isOpen ? 'beforeopen' : 'beforeclose';
        var afterEvent = this.dropEl.isOpen ? 'close' : 'open';
        if (this.element.dispatchEvent(UIInternal.createEvent(beforeEvent)) !== false) {
            this.dropEl.toggleDrop();
            this.element.dispatchEvent(UIInternal.createEvent(afterEvent));
        }
        return false;
    };
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "label", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "href", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "icon", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "iconColor", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "color", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "id", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", String)
    ], UIMenuItem.prototype, "classes", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Boolean)
    ], UIMenuItem.prototype, "active", void 0);
    __decorate([
        bindable(),
        __metadata("design:type", Boolean)
    ], UIMenuItem.prototype, "disabled", void 0);
    __decorate([
        child('.ui-drop'),
        __metadata("design:type", Element)
    ], UIMenuItem.prototype, "elDropdown", void 0);
    __decorate([
        computedFrom('iconColor', 'color'),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], UIMenuItem.prototype, "uiColor", null);
    UIMenuItem = __decorate([
        customElement('ui-menu-item'),
        __metadata("design:paramtypes", [Element])
    ], UIMenuItem);
    return UIMenuItem;
}());

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