@page "/Account/Manage"

@using System.ComponentModel.DataAnnotations
@using Microsoft.AspNetCore.Identity

<MudPaper Class="flex-grow-1">

	<div class="row">
		<div class="col-md-6">
			<EditForm Model="Input" FormName="profile" OnValidSubmit="OnValidSubmitAsync" method="post">
				<DataAnnotationsValidator />
				<ValidationSummary class="text-danger" role="alert" />
				<div class="form-floating mb-3">
					<input type="text" value="@username" class="form-control" placeholder="Please choose your username." disabled />
					<label for="username" class="form-label">Username</label>
				</div>
				<div class="form-floating mb-3">
					<InputText @bind-Value="Input.PhoneNumber" class="form-control" placeholder="Please enter your phone number." />
					<label for="phone-number" class="form-label">Phone number</label>
					<ValidationMessage For="() => Input.PhoneNumber" class="text-danger" />
				</div>
				<button type="submit" class="w-100 btn btn-lg btn-primary">Save</button>
			</EditForm>
		</div>
	</div>

</MudPaper>
@code {

	private string? username;
	private string? phoneNumber;

	[CascadingParameter]
	private Task<AuthenticationState> authenticationStateTask { get; set; }

	[SupplyParameterFromForm]
	private InputModel Input { get; set; } = new();

	protected override async Task OnInitializedAsync()
	{
		username = authenticationStateTask.Result.User.Identity.Name;
		phoneNumber = authenticationStateTask.Result.User.Identity.IsAuthenticated.ToString();

		Input.PhoneNumber ??= phoneNumber;
	}

	private async Task OnValidSubmitAsync()
	{

	}

	private sealed class InputModel
	{
		[Phone]
		[Display(Name = "Phone number")]
		public string? PhoneNumber { get; set; }
	}
}
