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

namespace DiplomovaPrace.Web.Admin.Pages.Security
{
	public partial class LoginForm
	{
		[Inject]
		private ILoginService LoginService { get; set; }

		[Inject]
		private NavigationManager NavigationManager { get; set; }

		private LoginAccountIM loginAccount = new();

		private string ReturnUrl { get; set; }

		private bool isLoginSuccessful = true;

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

			ReturnUrl = NavigationManager.ExtractQueryStringByKey<string>("returnUrl");
		}

		private async Task HandleSubmitAsync()
		{
			isLoginSuccessful = await LoginService.LoginAdminAsync(loginAccount, ReturnUrl).ConfigureAwait(false);
		}
	}
}
