ildar-shaymukhametov_grandnode-refactorings/Grand.Web/Areas/Admin/Views/Shared/_AdminLayout.cshtml
@inject IWebHelper webHelper
@inject IWorkContext workContext
@inject IPermissionService permissionService
@inject CommonSettings commonSettings
@inject CustomerSettings customerSettings
@inject LocalizationSettings localizationSettings
@inject AdminAreaSettings adminAreaSettings
@inject Grand.Core.Configuration.GrandConfig grandConfig
@inject IPageHeadBuilder pagebuilder

@using System.Text.Encodings.Web
@using Grand.Domain.Customers
@using Grand.Framework.UI;
@using Grand.Core;
@using Grand.Domain.Localization
@using Grand.Services.Security;
@using Grand.Domain.Common;
@{
    var currentCustomer = workContext.CurrentCustomer;
    var usernamesEnabled = customerSettings.UsernamesEnabled;
    var currentVersion = GrandVersion.FullVersion;
    var kendoVersion = "2019.2.514";
    var supportRtl = workContext.WorkingLanguage.Rtl &&
        !localizationSettings.IgnoreRtlPropertyForAdminArea;

    //CSS
    if (supportRtl)
    {
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, string.Format("~/content/kendo/{0}/kendo.rtl.min.css", kendoVersion), excludeFromBundle: true);
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/build/css/custom-rtl.css", excludeFromBundle: true);
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/bootstrap/css/bootstrap-rtl.min.css", excludeFromBundle: true);
    }
    else
    {
        pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/build/css/custom.css", excludeFromBundle: true);
    }
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, string.Format("~/content/kendo/{0}/kendo.common-material.min.css", kendoVersion), excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, $"~/content/kendo/{kendoVersion}/kendo.material.min.css", excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, $"~/content/kendo/{kendoVersion}/kendo.material.mobile.min.css", excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/content/jquery-ui-themes/smoothness/jquery-ui-1.10.3.custom.min.css", excludeFromBundle: true);
    pagebuilder.AddScriptParts(location: ResourceLocation.Footer, src: "~/content/tinymce/tinymce.min.js", excludeFromBundle: true);

    //administration

    pagebuilder.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/build/js/custom.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/build/js/smartresize.js", excludeFromBundle: true);

    //vendors

    pagebuilder.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/bootstrap/js/bootstrap.min.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(location: ResourceLocation.Footer, src: "~/administration/bootstrap/js/popper.min.js", excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/bootstrap/css/bootstrap.min.css", excludeFromBundle: true);


    //js
    //available list of culture https://github.com/telerik/kendo-ui-core/tree/master/src/cultures
    pagebuilder.AppendScriptParts(ResourceLocation.Head, string.Format("~/scripts/kendo/{0}/cultures/kendo.culture.{1}.min.js", kendoVersion, "en-US"), excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, string.Format("~/scripts/kendo/{0}/kendo.grid.js", kendoVersion), excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, string.Format("~/scripts/kendo/{0}/kendo.ui.core.min.js", kendoVersion), excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/admin.common.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/jquery-ui-1.12.1.custom/jquery-ui.min.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/jquery.validate.unobtrusive.min.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/jquery.validate.min.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/admin.search.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/scripts/typeahead.js", excludeFromBundle: true);

    pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/simple-line-icons/simple-line-icons.min.css", excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/build/css/font-awesome.min.css", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/administration/bootstrap/js/daterangepicker.min.js", excludeFromBundle: true);
    pagebuilder.AppendCssFileParts(ResourceLocation.Head, "~/administration/bootstrap/css/daterangepicker.min.css", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/administration/build/js/moment.min.js", excludeFromBundle: true);
    pagebuilder.AppendScriptParts(ResourceLocation.Head, "~/administration/build/js/jquery.min.js", excludeFromBundle: true);

    //page title
    string adminPageTitle = "";
    if (!String.IsNullOrWhiteSpace(ViewBag.Title))
    {
        adminPageTitle = ViewBag.Title + " / ";
    }
    adminPageTitle += T("Admin.PageTitle").Text;

    //has "Manage Maintenance" permission?
    var canManageMaintenance = await permissionService.Authorize(StandardPermissionProvider.ManageMaintenance);

}
<!DOCTYPE html>
<html @if (supportRtl) { <text> dir="rtl" </text> } onloadstart="myFunction()">
<head>
    <title>@adminPageTitle</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <head-custom>
        <css-files asp-location="Head" bundle-files="false">
            <script-files asp-location="Head" bundle-files="false">
</head>
<body>
    @Html.AntiForgeryToken()
    <script>
        if (document.readyState == "loading") {
            let value = localStorage.getItem("sideBarCookie");
            if (value == "true") {
                $('body').removeClass('nav-md');
                $('body').addClass('nav-sm');
                $(".site_title").css("padding-left", "26px");
                if ($('body').hasClass('nav-sm')) {
                    $('#sidebar-menu').find('li.active').addClass('active-sm').removeClass('active');
                    $('#sidebar-menu').find('li.active-sm ul').hide();
                }
            }
            else {
                $('body').removeClass('nav-sm');
                $('body').addClass('nav-md');
                $(".site_title").css("padding-left", "0px");
                $('#sidebar-menu').find('li.active-sm').addClass('active').removeClass('active-sm');
                $('#sidebar-menu').find('li.active > ul').show();
            }
        }

    </script>
    <div class="container body">
        <div class="main_container">
            <vc:admin-widget widget-zone="admin_header_before" additional-data="null" />
            @if (IsSectionDefined("headermenu"))
            {
                @RenderSection("headermenu")
            }
            else
            {
                <partial name="Menu" />
            }
            <vc:admin-widget widget-zone="admin_header_after" additional-data="null" />
            @if (IsSectionDefined("statusbar"))
            {
                @RenderSection("statusbar")
            }
            @if (IsSectionDefined("header"))
            {
                @RenderSection("header")
            }
            else
            {
                <vc:admin-widget widget-zone="header_before" additional-data="null" />
                <div class="top_nav">
                    <div class="nav_menu">
                        <nav>
                            <div class="nav toggle">
                                <a id="menu_toggle">
                                    <span></span>
                                    <span></span>
                                    <span></span>
                                </a>
                            </div>

                            @if (currentCustomer.IsAdmin())
                            {
                                <div class="admin-search-input-container">
                                    <input id="searchInput" type="text" class="form-control" placeholder="@T("Admin.AdminSearch.Placeholder")">
                                    <script>
                                      $(document).ready(function () {
                                        Admin.Search.init("@(Url.Action("Index", "Search"))");
                                      });
                                    </script>
                                </div>
                            }
                            <vc:admin-widget widget-zone="header_toggle_after" additional-data="null" />
                            <ul class="nav navbar-nav navbar-right">

                                <li class="dropdown" role="presentation">
                                    <a href="@Url.Action("Index", "Home", new { area = "" })" class="dropdown-toggle">
                                        <i class="icon-home"></i>
                                    </a>
                                </li>
                                <li role="presentation" class="dropdown">
                                    <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                                        <i class="icon-info"></i>
                                    </a>
                                    <ul id="menu1" class="dropdown-menu dropdown-menu-right list-unstyled msg_list overflow-h" role="menu">
                                        <li>
                                            <a href="http://docs.grandnode.com/" target="_blank">
                                                <i class="icon-book-open"></i>
                                                @T("Admin.Header.Documentation")
                                            </a>
                                        </li>
                                        <li>
                                            <a href="https://grandnode.com/boards" target="_blank">
                                                <i class="icon-bubbles"></i>
                                                @T("Admin.Header.Community")
                                            </a>
                                        </li>
                                        <li>
                                            <a href="https://grandnode.com/release-notes" target="_blank">
                                                <i class="fa fa-dot-circle-o"></i>
                                                grandnode @currentVersion
                                            </a>
                                        </li>
                                    </ul>
                                </li>
                                @if (canManageMaintenance)
                                {
                                    <li role="presentation" class="dropdown">
                                        <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                                            <i class="icon-settings"></i>
                                        </a>
                                        <ul id="menu1" class="dropdown-menu dropdown-menu-right list-unstyled msg_list overflow-h" role="menu">
                                            <li>
                                                <a href="@Url.Action("ClearCache", "Common", new { memory = true, returnurl = webHelper.GetRawUrl(this.Context.Request) })">
                                                    <i class="icon-refresh"></i>
                                                    @T("Admin.Header.ClearCacheMemory")
                                                </a>
                                            </li>

                                            <li>
                                                <a href="@Url.Action("RestartApplication", "Common", new { returnurl = webHelper.GetRawUrl(this.Context.Request) })" id="restart-application">
                                                    <i class="icon-reload"></i>
                                                    @T("Admin.Header.RestartApplication")
                                                </a>
                                            </li>

                                        </ul>
                                    </li>
                                }
                                <li>
                                    <a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <img src="~/administration/build/images/avatar.png" alt="">

                                        @if (currentCustomer != null && currentCustomer.IsRegistered())
                                        {
                                            <div class="username-hide-on-mobile">
                                                @(usernamesEnabled ? currentCustomer.Username : currentCustomer.Email)
                                            </div>

                                        }
                                        <span class="fa fa-angle-down"></span>
                                    </a>

                                    <ul class="dropdown-menu dropdown-menu-right dropdown-menu-default">
                                        @if (currentCustomer.IsAdmin())
                                        {
                                            <li>
                                                <a href="@Url.Action("Edit", "Customer", new { id = currentCustomer.Id, area = Constants.AreaAdmin })">
                                                    <i class="icon-user"></i> @T("Admin.Header.Profile")
                                                </a>
                                            </li>
                                        }
                                        <li>
                                            <a href="@Url.Action("Logout", "Customer", new { area = "" }, null)">
                                                <i class="icon-logout"></i> @T("Admin.Header.Logout")
                                            </a>
                                        </li>
                                    </ul>
                                </li>


                                @await Component.InvokeAsync("CommonLanguageSelector")
                                <li class="dropdown" role="presentation">
                                    <span id="searchIcon" class="searchIcon dropdown-toggle">
                                        <i class="icon-magnifier"></i>
                                    </span>
                                </li>
                                <li class="dropdown version-check" role="presentation" id="version_check">
                                    <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                        <i class="icon-bell"></i>
                                    </a>
                                    <script>
                                        $.getJSON("https://grandnode.com/version.json", function (data) {
                                            var items = [];

                                            if (data == '@currentVersion') {
                                                items.push("<li><a><span class='badge badge-success'>The application is up to date<span></a></li>");
                                                $("<span class='success info-indicator'></span>").appendTo("#version_check .dropdown-toggle");
                                            } else {
                                                items.push("<li><a><span class='badge badge-danger'>There is a new version of the application<span></a></li>");
                                                $("<span class='danger info-indicator'></span>").appendTo("#version_check .dropdown-toggle");
                                            }

                                            $("<ul/>", {
                                                "class": "dropdown-menu dropdown-menu-right dropdown-menu-default",
                                                html: items.join("")
                                            }).appendTo("#version_check");
                                        });
                                    </script>
                                </li>
                                <li role="presentation">
                                    <a>
                                        <div class="custom-control custom-switch light-dark-switch">
                                            <input type="checkbox" class="custom-control-input" id="DarkLight">
                                            <label class="custom-control-label" for="DarkLight">Enable Dark Mode</label>
                                        </div>
                                    </a>
                                    <script>
                                        const toggleSwitch = document.querySelector('.light-dark-switch input[type="checkbox"]');
                                        const currentTheme = localStorage.getItem('theme');

                                        if (currentTheme) {
                                            document.documentElement.setAttribute('data-theme', currentTheme);

                                            if (currentTheme === 'dark') {
                                                toggleSwitch.checked = true;
                                                $('#DarkLight ~ label').text('Disable Dark Mode');
                                            }
                                        }

                                        function switchTheme(e) {
                                            if (e.target.checked) {
                                                document.documentElement.setAttribute('data-theme', 'dark');
                                                localStorage.setItem('theme', 'dark');
                                                $('#DarkLight ~ label').text('Disable Dark Mode');

                                            }
                                            else {
                                                document.documentElement.setAttribute('data-theme', 'light');
                                                localStorage.setItem('theme', 'light');
                                                $('#DarkLight ~ label').text('Enable Dark Mode');
                                            }
                                        }

                                        toggleSwitch.addEventListener('change', switchTheme, false);
                                    </script>
                                </li>
                            </ul>
                        </nav>
                    </div>
                    <div class="clear"></div>
                </div>
                <vc:admin-widget widget-zone="header_navbar_after" additional-data="null" />
            }

            <div class="right_col" role="main">
                <partial name="Notifications" />
                @RenderBody()
            </div>
            <div class="throbber">
                <div class="curtain">
                </div>
                <div class="curtain-content">
                    <div>
                        <h1 class="throbber-header">Wait...</h1>
                        <div class="spinner active">
                            <svg style="width:100px; height:100px" viewBox="0 0 64 64">
                                <circle cx="32" cy="32" r="29" fill="none" stroke-width="3" stroke-miterlimit="10"></circle>
                            </svg>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <css-files asp-location="Footer">
        <script-files asp-location="Footer">

            <div class="page-footer">
                <div class="page-footer-inner">
                    <a href="https://grandnode.com/" target="_blank">@DateTime.UtcNow.Year Powered by GrandNode ®</a>
                </div>
                <div class="scroll-to-top">
                    <i class="icon-arrow-up"></i>
                </div>
            </div>
            <script>
            $(document).ready(function () {
                $("#restart-application").click(function (e) {
                    event.preventDefault();
                    showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(T("Admin.Header.RestartApplication.Progress").Text))');
                    $("html, body").animate({ scrollTop: 0 }, 400);
                    $.get($(this).attr("href"), function (data) { });
                    setTimeout(function () {
                        location.reload();
                    }, 10000);
                });
            });
            </script>
</body>
</html>