using System.Threading.Tasks;
using DiplomovaPrace.Contracts.Security.InputModels;
using DiplomovaPrace.Web.Admin.Services;
using Microsoft.AspNetCore.Components;

namespace DiplomovaPrace.Web.Admin.Pages.Security
{
	public partial class ResetPasswordForm
	{
		[Parameter]
		public string Token { get; set; }

		[Inject]
		private ISecurityService SecurityService { get; set; }

		private PasswordResetIM newPassword = new();

		protected override async Task OnInitializedAsync()
		{
			await base.OnInitializedAsync().ConfigureAwait(false);

			await SecurityService.ValidateTokenAsync(Token).ConfigureAwait(false);
		}

		public async Task HandleSubmitAsync()
		{
			newPassword.Token = Token;
			await SecurityService.PasswordResetAsync(newPassword).ConfigureAwait(false);
		}
	}
}
