@page "/"
@page "/{UserId}"

@inject ApiClient Api
@inject NavigationManager Navigation
@inject UserContext UserContext

<PageTitle>ASTRAIN</PageTitle>

<div class="page-center">
	<div class="card">
		<h1>ASTRAIN</h1>
		<p>Preparing your training logbook...</p>
	</div>
</div>

@code {
	[Parameter]
	public string? UserId { get; set; }

	protected override async Task OnInitializedAsync()
	{
		var ensured = await Api.EnsureUserAsync(UserId);
		if (string.IsNullOrWhiteSpace(ensured))
		{
			return;
		}

		UserContext.SetUserId(ensured);
		var target = $"/{ensured}/routines";
		if (!Navigation.Uri.EndsWith(target, StringComparison.OrdinalIgnoreCase))
		{
			Navigation.NavigateTo(target, true);
		}
	}
}
