text: (function() {
    'use strict';
  
    angular.module('BlurAdmin.theme.components')
        .provider('baSidebarService', baSidebarServiceProvider);
  
    /** @ngInject */
    function baSidebarServiceProvider() {
      var staticMenuItems = [];
  
      this.addStaticItem = function() {
        staticMenuItems.push.apply(staticMenuItems, arguments);
      };
  
      /** @ngInject */
      this.$get = function($state, layoutSizes) {
        return new _factory();
  
        function _factory() {
          var isMenuCollapsed = shouldMenuBeCollapsed();
  
          this.getMenuItems = function() {
            var user = {},
            defaultRoles = ['guest']
            try {
              user = JSON.parse(localStorage.getItem('currentUser'))
              defaultRoles = defaultRoles.concat(user.roles)
            } catch(e) {
              defaultRoles = ['guest']
            }
            var states = defineMenuItemStates()
            // console.log(states);
            var menuItems = states.filter(function(item) {
              if (item.level !== 0) return false
              if (!item.role) item.role = 'guest'
              // console.log(defaultRoles, item, defaultRoles.indexOf(item.role) > -1 && item.level == 0)
              return defaultRoles.indexOf(item.role) > -1 && item.level == 0;
            });
  
            menuItems.forEach(function(item) {
              // console.log(item)
              var children = states.filter(function(child) {
                return child.level == 1 && child.name.indexOf(item.name) === 0;
              });
              item.subMenu = children.length ? children : null;
            });
  
            return menuItems.concat(staticMenuItems);
          };
  
          this.shouldMenuBeCollapsed = shouldMenuBeCollapsed;
          this.canSidebarBeHidden = canSidebarBeHidden;
  
          this.setMenuCollapsed = function(isCollapsed) {
            isMenuCollapsed = isCollapsed;
          };
  
          this.isMenuCollapsed = function() {
            return isMenuCollapsed;
          };
  
          this.toggleMenuCollapsed = function() {
            isMenuCollapsed = !isMenuCollapsed;
          };
  
          this.getAllStateRefsRecursive = function(item) {
            var result = [];
            _iterateSubItems(item);
            return result;
  
            function _iterateSubItems(currentItem) {
              currentItem.subMenu && currentItem.subMenu.forEach(function(subItem) {
                subItem.stateRef && result.push(subItem.stateRef);
                _iterateSubItems(subItem);
              });
            }
          };
  
          function defineMenuItemStates() {
            // console.log()
            return $state.get()
                .filter(function(s) {
                  return s.sidebarMeta;
                })
                .map(function(s) {
                  var meta = s.sidebarMeta;
                  return {
                    name: s.name,
                    title: s.title,
                    level: (s.name.match(/\./g) || []).length,
                    order: meta.order,
                    icon: meta.icon,
                    stateRef: s.name,
                    role: s.role
                  };
                })
                .sort(function(a, b) {
                  return (a.level - b.level) * 100 + a.order - b.order;
                });
          }
  
          function shouldMenuBeCollapsed() {
            return window.innerWidth <= layoutSizes.resWidthCollapseSidebar;
          }
  
          function canSidebarBeHidden() {
            return window.innerWidth <= layoutSizes.resWidthHideSidebar;
          }
        }
  
      };
  
    }
  })();
  