@using MrCMS.Website
@model MrCMS.Web.Apps.Core.Models.Navigation.NavigationList
@{
    var currentPage = CurrentRequestData.CurrentPage;
    var activePages = currentPage.ActivePages.Select(webpage => "/" + webpage.LiveUrlSegment).ToList();
}
<ul class="nav">
    @foreach (var page in Model)
    {
        if (page.Children.Any())
        {
            <li>
                <a href="@page.Url" class="dropdown-toggle" data-toggle="dropdown">@page.Text</a>
                <ul>
                    @foreach (var record in page.Children)
                    {
                        if (record.Children.Any())
                        {
                            <li>
                                <a href="@record.Url">@record.Text</a>
                                @Html.Partial("_ChildCategories", record)
                            </li>
                        }
                        else
                        {
                            <li class="@(activePages.Contains(record.Url.ToString(), StringComparer.OrdinalIgnoreCase) ? "active" : "")">
                                <a href="@record.Url">@record.Text</a>
                            </li>
                        }
                    }
                </ul>
            </li>
        }
        else
        {
            <li class="@(activePages.Any(s => s == page.Url.ToString()) ? "active" : "")">
                <a href="@page.Url">@page.Text</a>
            </li>
        }
    }
</ul>
