using System;
using System.Diagnostics;
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 APageComponent {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public bool Page_WasPrepared { get; private set; }

public void Page_Prepare()
{
   Page_Invoke( "Prepare" );
   Page_WasPrepared = true;
}
public void Page_Prepare(params object?[] args)
{
   Page_Invoke( "Prepare", args );
   Page_WasPrepared = true;
}

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

public void Page_Invoke(string identifier,params object?[] args) =>
   UJS.Invoke( PageMethodIdentifierJS( identifier ), args );

public TResult Page_Invoke<TResult>(string identifier,params object?[] args) =>
   UJS.Invoke<TResult>( PageMethodIdentifierJS( identifier ), args );

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

public ValueTask Page_Invoke_A(string identifier,params object?[] args) =>
   UJS.Invoke_A( PageMethodIdentifierJS( identifier ), args );

public ValueTask<TResult> Page_Invoke_A<TResult>(string identifier,params object?[] args) =>
   UJS.Invoke_A<TResult>( PageMethodIdentifierJS( identifier ), args );

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

public bool SaveFocus( AComponent control,
                       bool withSelectRestoring = false ) =>
   UPage.SaveFocus( control.MainElement, withSelectRestoring );

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

string PageMethodIdentifierJS(string identifier) =>
   string.Format( "{0}_{1}", GetType().Name, identifier );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // APageComponent
//**************************************************************************************************

} // BookRegistry.Client
