using Avalonia.Controls;
using System.Threading.Tasks;

namespace LibationAvalonia.Dialogs.Login
{
	public partial class _2faCodeDialog : DialogWindow
	{
		public string Code { get; set; }
		public string Prompt { get; } = "For added security, please enter the One Time Password (OTP) generated by your Authenticator App";


		public _2faCodeDialog()
		{
			InitializeComponent();
			_2FABox = this.FindControl<TextBox>(nameof(_2FABox));
		}

		public _2faCodeDialog(string prompt) : this()
		{
			Prompt = prompt;
			DataContext = this;
			Opened += (_, _) => _2FABox.Focus();
		}

		protected override Task SaveAndCloseAsync()
		{
			Serilog.Log.Logger.Information("Submit button clicked: {@DebugInfo}", new { Code });

			return base.SaveAndCloseAsync();
		}

		public async void Submit_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
			=> await SaveAndCloseAsync();
	}
}
