@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb.Frontend.Navigation
@using Dynamicweb.Content

@{
	int rootPageId = GetPageIdByNavigationTag("SignInPage") != 0 ? GetPageIdByNavigationTag("SignInPage") : Pageview?.ID ?? 0;
	if (Model.Item?.TryGetLink("SignInPage", out var signInPage) ?? false)
	{
		rootPageId = signInPage?.PageId ?? 0;
	}

	var nav = Navigation.GetNavigationViewModel(new()
	{
		RootPageId = rootPageId,
		ExpandMode = ExpandMode.All
	});
}

@if (((Pageview?.User is null) || (Pageview?.IsVisualEditorMode ?? false)) && (nav?.Nodes.Any() ?? false))
{
	<div class="nav-wrapper" data-swift-menu="@Model.ID">
		<div class="nav-item dropdown position-static">
			<a href="/Default.aspx?ID=@rootPageId" class="nav-link hstack gap-2 p-2 text-nowrap text-decoration-underline-hover" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="SignInDropdown_@Model.ID">
				@if (Model.Item?.TryGetString("Icon", out var icon) ?? false && icon.Contains(".svg"))
				{
					<span class="icon-3 pe-none">@ReadFile(icon)</span>
				}
				@if (Model.Item?.TryGetString("Title", out string? title) ?? false)
				{
					@title
				}
			</a>
			<ul class="dropdown-menu dropdown-menu-shadow" aria-labelledby="SignInDropdown_@Model.ID" data-dw-colorscheme="light">			
				@foreach (var node in nav.Nodes)
				{
					<li>
						<a class="dropdown-item" @(node.IsClickable ? $"href=\"{node.Link}\"" : null) @(node.IsActive ? "aria-current='page'" : null)>
							<span class="@(!node.IsClickable ? "pe-none" : null)">@(node.Name)</span>
						</a>
					</li>
				}
			</ul>
		</div>
	</div>
}
