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

using CommonHelpers.WASM;

namespace AFXUI {

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

[Conditional("DEBUG")]
static void PrintMethodTitle(TraceParameters tp) =>
   Trace( tp.TraceOptions, "=== {0}[{1}] {2}: ===",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );
[Conditional("DEBUG")]
static void PrintOuterMethodOut(TraceParameters tp) =>
   Trace( tp.TraceOptions, "<== {0}[{1}] {2}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );

[Conditional("DEBUG")]
static void PrintShallowTitle(TraceParameters tp) =>
   Trace( tp.TraceOptions, "--- {0}[{1}] {2}: ---",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );
[Conditional("DEBUG")]
static void PrintShallowOut(TraceParameters tp) =>
   Trace( tp.TraceOptions, "<-- {0}[{1}] {2}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );

[Conditional("DEBUG")]
static void PrintInnerMethodIn(TraceParameters tp) =>
   Trace( tp.TraceOptions, "--> {0}[{1}:+{2}] {3}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name,
      _ExclusiveLevels_[ tp.Level ].SyncEntryCount_Visible-1,
      tp.MethodNameOrSignature );
[Conditional("DEBUG")]
static void PrintInnerMethodOut(TraceParameters tp) =>
   Trace( tp.TraceOptions, "<-- {0}[{1}:+{2}] {3}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name,
      _ExclusiveLevels_[ tp.Level ].SyncEntryCount_Visible-1,
      tp.MethodNameOrSignature );

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

[Conditional("DEBUG")]
static void PrintAsyncShallowIn(TraceParameters tp) =>
   Trace( tp.TraceOptions, "~~> {0}[{1}] {2}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );
[Conditional("DEBUG")]
static void PrintAsyncShallowOut(TraceParameters tp) =>
   Trace( tp.TraceOptions, "<~~ {0}[{1}] {2}",
      LevelNumOrEmpty(tp.Level), tp.Type.Name, tp.MethodNameOrSignature );

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

static string LevelNumOrEmpty(int level) =>
   level>0 ? HRomanNumerals.Format(level)+": " : "";

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

[Conditional("DEBUG")]
static void Trace(UFuncTraceOptions traceOptions,string message)
{
   if ( !NoTrace( traceOptions ) )
      UDebugConsole.Print( message );
}
[Conditional("DEBUG")]
static void Trace(UFuncTraceOptions traceOptions,string messageFmt,params object?[] args)
{
   if ( !NoTrace( traceOptions ) )
      Trace( traceOptions, HString.FormatAsText( messageFmt, args ) );
}

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

static bool NoTrace(UFuncTraceOptions traceOptions) =>
   (traceOptions & UFuncTraceOptions.NoTrace) != 0;
static bool TraceFuncExit(UFuncTraceOptions traceOptions) =>
   (traceOptions & UFuncTraceOptions.TraceFuncExit) != 0;

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

} // AFXUI
