@model TopMenuModel
@using Nop.Core.Domain.Catalog
@using Nop.Core.Domain.Topics

<div class="main-menu">
    <nav class="navbar navbar-inverse category-menu">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button aria-expanded="false" data-target="#mobile-menu" data-toggle="collapse" class="navbar-toggle collapsed" type="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="mobile-menu" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.HeaderMenuBefore, additionalData = Model })
                @if (Model.DisplayHomepageMenuItem)
                {
                    <li><a href="@Url.RouteUrl("Homepage")">@T("Homepage")</a></li>
                }
                @if (!Model.UseAjaxMenu)
                {
                    var rootCategories = Model.Categories.Where(x => x.IncludeInTopMenu).ToList();
                    @foreach (var category in rootCategories)
                    {
                        var categoryLineModel = new TopMenuModel.CategoryLineModel
                        {
                            Category = category
                        };
                        @await Html.PartialAsync("_CategoryLine.TopMenu", categoryLineModel)
                    }
                }
                @foreach (var topic in Model.Topics)
                {
                    <li><a href="@(Url.RouteUrl<Topic>(new { SeName = topic.SeName }))">@topic.Name</a></li>
                }
                @if (Model.NewProductsEnabled && Model.DisplayNewProductsMenuItem)
                {
                    <li><a href="@Url.RouteUrl("NewProducts")">@T("Products.NewProducts")</a></li>
                }
                @if (Model.DisplayProductSearchMenuItem)
                {
                    <li><a href="@Url.RouteUrl("ProductSearch")">@T("Search")</a></li>
                }
                @if (Model.DisplayCustomerInfoMenuItem)
                {
                    <li><a href="@Url.RouteUrl("CustomerInfo")">@T("Account.MyAccount")</a></li>
                }
                @if (Model.BlogEnabled && Model.DisplayBlogMenuItem)
                {
                    <li><a href="@Url.RouteUrl("Blog")">@T("Blog")</a></li>
                }
                @if (Model.ForumEnabled && Model.DisplayForumsMenuItem)
                {
                    <li><a href="@Url.RouteUrl("Boards")">@T("Forum.Forums")</a></li>
                }
                @if (Model.DisplayContactUsMenuItem)
                {
                    <li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>
                }
                @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.HeaderMenuAfter, additionalData = Model })
            </ul>
        </div><!-- /.navbar-collapse -->
    </nav>
</div>
@if (Model.UseAjaxMenu)
{
    <script asp-location="Footer">
            $(document).ready(function () {
                $("#mobile-menu .dropdown .fa-angle-down").click(function () {
                    var $this = $(this);
                    $this.siblings("ul.dropdown-menu").slideToggle("slow", function () {
                        if ($this.siblings("ul.dropdown-menu").css('display') == 'block')
                            $this.addClass("rotate");
                        else if ($this.siblings("ul.dropdown-menu").css('display') == 'none')
                            $this.removeClass("rotate");
                    });
                });
                var localized_data = {
                    AjaxFailure: "@T("MainMenu.AjaxFailure")"
                };
                mainMenu.init('@Url.RouteUrl("GetCatalogRoot")', '@Url.RouteUrl("GetCatalogSubCategories")', 'ul.top-menu.notmobile', 'ul.top-menu.mobile', localized_data);
            });
    </script>
    <script src="~/js/public.menu.js" asp-location="Footer"></script>
}
else
{
    <script asp-location="Footer">
        $(document).ready(function () {
            $("#mobile-menu .dropdown .fa-angle-down").click(function () {
                var $this = $(this);
                $this.siblings("ul.dropdown-menu").slideToggle("slow", function () {
                    if ($this.siblings("ul.dropdown-menu").css('display') == 'block')
                        $this.addClass("rotate");
                    else if ($this.siblings("ul.dropdown-menu").css('display') == 'none')
                        $this.removeClass("rotate");
                });
            });
        });
    </script>
}