//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// AFXUI auxiliary module for Blazor-application (WASM) | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;

using CommonHelpers.WASM;

namespace AFXUI {

//**************************************************************************************************
static partial class UCircuit {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static Task<int> DoBlocking_A( this ComponentBase component, Func<Task> bodyA,
                                      [CallerMemberName] string? methodNameOrSignature=null ) =>
   DoBlocking_A( component, new UCircuitExtraParams(), bodyA, methodNameOrSignature );
public static Task<int> DoBlocking_A( this ComponentBase component,
                                      Func<bool>? preliminary, Func<Task> bodyA,
                                      [CallerMemberName] string? methodNameOrSignature=null ) =>
   DoBlocking_A( component, new UCircuitExtraParams(), preliminary, bodyA, methodNameOrSignature );

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

public static Task<int> DoBlocking_A( this ComponentBase component,
                                      bool useWaitingCursor, Func<Task> bodyA,
                                      [CallerMemberName] string? methodNameOrSignature=null ) =>
   DoBlocking_A( component, useWaitingCursor, new UCircuitExtraParams(), bodyA,
                 methodNameOrSignature );
public static Task<int> DoBlocking_A( this ComponentBase component,
                                      bool useWaitingCursor,
                                      Func<bool>? preliminary, Func<Task> bodyA,
                                      [CallerMemberName] string? methodNameOrSignature=null ) =>
   DoBlocking_A( component, useWaitingCursor, new UCircuitExtraParams(), preliminary, bodyA,
                 methodNameOrSignature );

//==================================================================================================

public static async Task<int> DoBlocking_A( this ComponentBase component,
                                            UCircuitExtraParams extraParams, Func<Task> bodyA,
                                            [CallerMemberName] string? methodNameOrSignature=null )
=>
   await UBreakdown.ReturnVal_A<int>(async()=>{
      if ( !CheckBlocking( component, methodNameOrSignature ) )
         return 0;
      using (new UInputBlocking())
         return await BaseDo_A( 1,
            component.GetType(), component, methodNameOrSignature, extraParams,
            bodyA );
   }) ?? Int32.MinValue+1;

public static async Task<int> DoBlocking_A( this ComponentBase component,
                                            UCircuitExtraParams extraParams,
                                            Func<bool>? preliminary, Func<Task> bodyA,
                                            [CallerMemberName] string? methodNameOrSignature=null )
=>
   await UBreakdown.ReturnVal_A<int>(async()=>{
      if ( !CheckBlocking( component, methodNameOrSignature ) )
         return 0;
      using (new UInputBlocking())
         return await BaseDo_A( 1,
            component.GetType(), component, methodNameOrSignature,
            extraParams, preliminary, bodyA );
   }) ?? Int32.MinValue+1;

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

public static async Task<int> DoBlocking_A( this ComponentBase component, bool useWaitingCursor,
                                            UCircuitExtraParams extraParams, Func<Task> bodyA,
                                            [CallerMemberName] string? methodNameOrSignature=null )
=>
   await UBreakdown.ReturnVal_A<int>(async()=>{
      if ( !CheckBlocking( component, methodNameOrSignature ) )
         return 0;
      using (new UInputBlocking(useWaitingCursor))
         return await BaseDo_A( 1,
            component.GetType(), component, methodNameOrSignature, extraParams,
            bodyA );
   }) ?? Int32.MinValue+1;

public static async Task<int> DoBlocking_A( this ComponentBase component, bool useWaitingCursor,
                                            UCircuitExtraParams extraParams,
                                            Func<bool>? preliminary, Func<Task> bodyA,
                                            [CallerMemberName] string? methodNameOrSignature=null )
=>
   await UBreakdown.ReturnVal_A<int>(async()=>{
      if ( !CheckBlocking( component, methodNameOrSignature ) )
         return 0;
      using (new UInputBlocking(useWaitingCursor))
         return await BaseDo_A( 1,
            component.GetType(), component, methodNameOrSignature, extraParams,
            preliminary, bodyA );
   }) ?? Int32.MinValue+1;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UCircuit
//**************************************************************************************************

} // AFXUI
