using System;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using Microsoft.AspNetCore.Components;

using CommonHelpers.WASM;
using AFXUI;

using BookRegistry.Client.Shared;

namespace BookRegistry.Client {

//**************************************************************************************************
partial class AComponent {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static Task ESC_ShowInputError_A(string message) =>
   ESC_ShowError_A( "Incorrect input", message );
public static async Task ESC_ShowInputError_A( string message,
                                               ElementReference? setFocusElement,
                                               bool withSelectFocusing = false )
{
   await ESC_ShowInputError_A( message );
   if ( setFocusElement != null )
      if ( withSelectFocusing )
         setFocusElement.FocusSelect();
      else
         setFocusElement.Focus();
}
public static async Task ESC_ShowInputError_A( string message,
                                               AComponent setFocusComponent,
                                               bool withSelectFocusing = false )
{
   await ESC_ShowInputError_A( message );
   if ( setFocusComponent != null )
      if ( withSelectFocusing )
         setFocusComponent.MainElement.FocusSelect();
      else
         setFocusComponent.Interop_Focus();
}

//--------------------------------------------------------------------------------------------------

public static Task ESC_ShowInputCorrectMsg_A() =>
   ESC_ShowMessage_A( "Input checking", "The input is correct.\n(No error was detected.)" );

//--------------------------------------------------------------------------------------------------

public static async Task<bool> ESC_CheckInput_A( AComponent control,
                                                 bool withSelectFocusing = false )
{
   string? message = control.Interop_ErrorMessage;
   if ( message == null )
      return true;
   if ( control!=null && withSelectFocusing )
      await ESC_ShowInputError_A( message, control.MainElement );
   else
   {
      await ESC_ShowInputError_A( message );
      control?.Interop_Focus();
   }
   return false;
}

//==================================================================================================
/*
public static string? InputVMCompose(params string?[] errorMessages)
{
   var sb = new StringBuilder();
   foreach (var message in errorMessages)
      if ( !string.IsNullOrWhiteSpace( message ) )
      {
         if ( sb.Length > 0 )
            sb.AppendLine();
         sb.Append( message.TrimEnd() );
      }
   return sb.Length > 0 ? sb.ToString() : null;
}
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // AComponent
//**************************************************************************************************

} // BookRegistry.Client
