@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel>
@using Dynamicweb
@using System.IO

@{
	bool parentIsActive = !string.IsNullOrEmpty(GetViewParameterString("ParentIsActive")) ? GetViewParameterBoolean("ParentIsActive") : false;

	var nodesParms = new Dictionary<string, object>();
	nodesParms.Add("ParentIsActive", parentIsActive);
}

@foreach (var node in Model.Nodes)
{
	var hasChildren = node.Nodes.Count() > 0;
	bool endLevel = node.IsActive && !hasChildren;

	if (!endLevel)
	{
		if (parentIsActive && !node.IsActive)
		{
			<li class="nav-item">
				<a class="btn btn-sm btn-secondary rounded-pill text-nowrap" data-dw-button="secondary" href="@node.Link">
					@node.Name
				</a>
			</li>
		}

		nodesParms["ParentIsActive"] = node.IsActive;
		@RenderPartial("Navigation/VerticalAndBreadcrumb/MobileNodes.cshtml", node, nodesParms)
	}
	else //Handle the special layout at the end level
	{
		foreach (var endNode in Model.Nodes)
		{
			if (!endNode.IsActive)
			{
				<li class="nav-item">
					<a class="btn btn-sm btn-secondary rounded-pill text-nowrap" data-dw-button="secondary" href="@endNode.Link">
						@endNode.Name
					</a>
				</li>
			}
		}
	}
}
