"use strict";
Vue.component('ibiz-group-menu', {
    template: "\n        <div class=\"ibiz-group-menu\">\n            <row>\n                <i-col span=\"24\" class=\"first-level\" v-for=\"first in menu.items\" v-if=\"first.items && first.items.length > 0\">\n                    <div class=\"first-level-title\">\n                        <h2>\n                            <span class=\"first-level-title-icon\">\n                                <i v-if=\"first.icon == ''\" :class=\"[first.iconcls == '' ? '' : first.iconcls ]\"></i>\n                                <img v-else :src=\"first.icon\"/>\n                            </span>\n                            <span class=\"first-level-title-text\">{{first.text}}</span>\n                        </h2>\n                    </div>\n                    <row>\n\t                    <i-col :xs=\"6\" v-for=\"second in first.items\" class=\"second-level\">\n\t\t                    <div @click=\"openMenu(second)\">\n                                <div class=\"second-level-icon\">\n                                    <i v-if=\"second.icon == ''\" :class=\"[second.iconcls == '' ? 'fa fa-cogs' : second.iconcls ]\"></i>\n                                    <img v-else :src=\"second.icon\"/>\n                                </div>\n                                <h4 class=\"second-level-text\">{{second.text}}</h4>\n                                \n                                <span v-if=\"counterdata[second.counterid] && counterdata[second.counterid] > 0\">\n                                    <badge :count=\"counterdata[second.counterid]\" :overflow-count=\"maxNumber\">\n                                    </badge>\n                                </span>\n\n\t\t                    </div>\n\t\t                </i-col>\n                    </row>\n                </i-col>\n            </row>\n        </div>\n    ",
    props: {
        menu: {
            type: Object
        },
        viewController: {
            type: Object
        }
    },
    data: function () {
        var data = {
            counterdata: {},
            uiCounterEvent: null,
            maxNumber: IBizEnvironment.AppMenuUICounterMaxNumber ? IBizEnvironment.AppMenuUICounterMaxNumber : 9999,
        };
        return data;
    },
    mounted: function () {
        this.subscribeUICounter();
    },
    destroyed: function () {
        this.unSubscribeUICounter();
    },
    methods: {
        subscribeUICounter: function () {
            var _this = this;
            if (!this.menu.getUICounterName() || Object.is(this.menu.getUICounterName(), '')) {
                return;
            }
            var UICounter = this.viewController.uicounters.get(this.menu.getUICounterName());
            this.counterdata = {};
            Object.assign(this.counterdata, UICounter.getData());
            this.uiCounterEvent = UICounter.on(IBizUICounter.COUNTERCHANGED).subscribe(function (data) {
                _this.counterdata = {};
                Object.assign(_this.counterdata, data);
            });
        },
        unSubscribeUICounter: function () {
            if (this.uiCounterEvent) {
                this.uiCounterEvent.unsubscribe();
            }
        },
        // 打开菜单节点
        openMenu: function (second) {
            if (second === void 0) { second = {}; }
            if (this.menu) {
                this.menu.onSelectChange(second);
            }
        }
    }
});
