(function (paw) {
    function MainMenuScannerHelper() {
        this.$elt = null;
        this.navItemsLookup = {};
    }

    MainMenuScannerHelper.prototype.setup = function ($elt) {
        this.$elt = $elt;
    };

    MainMenuScannerHelper.prototype.getItem = function (itemId) {
        return this.navItemsLookup[itemId];
    };

    MainMenuScannerHelper.prototype.scanNavigationItems = function (parent) {
        var self = this;
        var items = [];
        var isParent = paw.utils.value.isSet(parent);

        var $lis = null;
        if (isParent) {
            $lis = parent.$originItem.find('> ul.dropdown-menu > li');
            if ($lis.length === 0) {
                return items;
            }
        }
        else {
            $lis = this.$elt.children('li[data-list-item-id]');
        }

        $lis.each(function () {
            var $item = $(this);
            var $itemSub = $item.children('ul.dropdown-menu');

            var item = {
                link: $($item.children('a')[0]).attr('href'),
                icon: $item.find('i').attr('class'),
                $originItem: $item,
                isDropdown: $itemSub.length > 0,
                isActive: $item.hasClass('active'),
                listItemId: $item.attr('data-list-item-id'),
                label: $item.find('> a > span').text(),
                parent: parent,
                isHidden: $item.hasClass('hidden-column')
            };

            if (paw.utils.value.notSet(item.label)) {
                item.label = $($item.children('a')[0]).text();
            }

            items.push(item);
            self.navItemsLookup[item.listItemId] = item;
        });
        return items;
    };

    paw.helper.mainMenuScanner = new MainMenuScannerHelper();
})(paw);