@using OurUmbraco.Documentation.Busineslogic.GithubSourcePull
@inherits Umbraco.Web.Macros.PartialViewMacroPage

@{
    var zipper = new ZipDownloader();
    dynamic sitemap = zipper.DocumentationSiteMap();
    var root = "/documentation";
}

@functions{
    public static string IsActive(string path, string classname = "active")
    {
        if (HttpContext.Current.Request.Url.PathAndQuery.ToLower().StartsWith(path.ToLower()))
            return classname;

        return string.Empty;
    }
}


<nav>
	<ul class="level-1">
	    @foreach (dynamic item in sitemap.directories)
        {
            if (item.name != "Development Guidelines" && item.name != "Extending Umbraco" && item.name != "Using Umbraco" && item.name != "Installation" && item.name != "Products" && item.name != "Cheatsheets")
            {
                <li class=" @IsActive(root+item.path, "active open")">
                    <a href="@(root + item.path)/"><h3>@item.name.ToString()</h3></a>
                    @if(item.hasChildren != null && (bool)item.hasChildren)
                    {
                        <ul class="level-2 @IsActive(root+item.path, "open")">
                            @foreach(dynamic itemChild in item.directories){
                            
                            <li class=" @IsActive(root+itemChild.path, "active open")">
					            <a href="@(root + itemChild.path)/"><h4>@itemChild.name.ToString()</h4></a>
                                @if(itemChild.hasChildren != null && (bool)itemChild.hasChildren) {
                                    <ul class="level-3 @IsActive(root+item.path, "open")"> 
                                        @foreach (dynamic itemGrandChild in itemChild.directories)
                                        {   
                                            <li class=" @IsActive(root+itemGrandChild.path, "active")"><a href="@(root + itemGrandChild.path)/"><h5>@itemGrandChild.name.ToString()</h5></a></li>
                                        }
                                    </ul>   
                                }
                            </li>
                            }
                        </ul>
                    }
                </li>
            }
        }
    </ul>
</nav>
