@using Grand.Business.Core.Interfaces.Common.Security
@using Grand.Business.Core.Interfaces.Common.Localization
@using Grand.Web.Common.Menu
@using Grand.Business.Core.Interfaces.System.Admin
@inject IPermissionService permissionService
@inject ITranslationService translationService
@inject IAdminSiteMapService adminSiteMapService
@inject IEnumerable<IAdminMenuProvider> _adminMenuProviders
@{
    //load sitemap
    var siteMap = new SiteMap(adminSiteMapService, permissionService);
    await siteMap.Load();
}
<div id="sidebar-button" class="sidebar_button" onclick="sidebarToggle()">
    <span></span>
    <span></span>
    <span></span>
</div>
<div class="col-md-3 left_col">
    <div class="left_col scroll-view">
        <div class="navbar nav_title">
            <a href="~/Admin" class="site_title"><img src="@(Common.WwwRoot)/administration/build/images/grandLogo.png" width="35" height="35" /> <span>GrandNode</span></a>
        </div>
        <div class="clearfix"></div>
        <div class="main_menu_side hidden-print main_menu" id="sidebar-menu">
            <div class="menu_section">
                <ul class="nav side-menu page-sidebar-menu">
                    @{
                        //standard (default) items
                        var rootNode = siteMap.RootNode;

                        //plugins
                        foreach (var adminMenuPlugin in _adminMenuProviders.ToList())
                        {
                            await adminMenuPlugin.ManageSiteMap(rootNode);
                        }
                        //"Plugins" menu item should be visible when it has some child nodes
                        var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
                        if (pluginNode != null && pluginNode.Visible)
                        {
                            var hasManagePluginsPermission = await permissionService.Authorize(Grand.Business.Core.Utilities.Common.Security.StandardPermission.ManagePlugins);
                            pluginNode.Visible = hasManagePluginsPermission && pluginNode.ChildNodes.Any(x => x.Visible);
                        }
                    }
                    @foreach (var item in rootNode.ChildNodes.Where(x => x.Visible))
                    {
                        <partial name="Partials/MenuItem" model="item" />
                    }
                </ul>
            </div>
        </div>
    </div>
</div>