@using Telerik.Web.Mvc.UI;
@using Nop.Web.Framework.Web;
@{
    if (!Telerik.Web.Mvc.SiteMapManager.SiteMaps.ContainsKey("admin"))
    {
        Telerik.Web.Mvc.SiteMapManager.SiteMaps.Register<Telerik.Web.Mvc.XmlSiteMap>("admin", sitemap =>
            sitemap.LoadFrom("~/Administration/sitemap.xml"));
    }
    var adminMenuPlugins = EngineContext.Current.Resolve<Nop.Core.Plugins.IPluginFinder>().GetPlugins<IAdminMenuPlugin>();
}
@{
    Html.Telerik().Menu().Name("Admin")
    .BindTo("admin", (item, siteMapNode) =>
    {
        var imageUrl = ((Telerik.Web.Mvc.SiteMapNode)siteMapNode).Attributes["ImageUrl"];
        if (imageUrl != null && !string.IsNullOrEmpty(imageUrl.ToString()))
        {
            item.ImageUrl = imageUrl.ToString();
        }
        
        var resourceName = ((Telerik.Web.Mvc.SiteMapNode)siteMapNode).Attributes["nopResource"];
        if (resourceName != null && !string.IsNullOrEmpty(resourceName.ToString()))
        {
            item.Text = T(resourceName.ToString()).ToHtmlString();
        }

        if (ViewBag.SelectedMenuItem == item.Text)
        {
            item.Selected = true;
        }
        
    })
    .Items(x =>
    {
        if (adminMenuPlugins.Count() > 0)
        {
            x.Add().Text(T("Plugins.Title").ToHtmlString()).Items(y =>
            {
                foreach (var adminMenuPlugin in adminMenuPlugins)
                {
                    adminMenuPlugin.BuildMenuItem(y.Add());
                }
            });
        }
    })
    .OpenOnClick(false)

    .Render();
}
