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

using CommonHelpers.WASM;

namespace AFXUI {

//**************************************************************************************************
public static partial class UHtmlElement {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public static bool HasId(this ElementReference? elementRef) =>
   GetId( elementRef ) != null;
public static string? GetId(this ElementReference? elementRef) =>
   elementRef.HasValue ? UJS.Invoke<string?>( "Element_GetId", elementRef.Value ) : null;

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

public static bool IsEnabled(this ElementReference? elementRef) =>
   elementRef.HasValue && !IsDisabled( elementRef );
public static bool IsDisabled(this ElementReference? elementRef) =>
   elementRef!=null ? UJS.Invoke<bool>( "Element_IsDisabled", elementRef.Value ) : false;

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

public static bool HasAttribute(this ElementReference? elementRef,string attributeName) =>
   elementRef.HasValue ? UJS.Invoke<bool>(
      "Element_HasAttribute", elementRef, attributeName )
      : false;
public static string? GetAttribute(this ElementReference? elementRef,string attributeName) =>
   elementRef.HasValue ? UJS.Invoke<string?>(
      "Element_GetAttribute", elementRef, attributeName)
      : null;
public static bool SetAttribute( this ElementReference? elementRef,
                                 string attributeName, string? value ) =>
   elementRef.HasValue ? UJS.Invoke<bool>(
      "Element_SetAttribute", elementRef, attributeName, value )
      : false;
public static bool RemoveAttribute(this ElementReference? elementRef,string attributeName) =>
   elementRef.HasValue ? UJS.Invoke<bool>(
      "Element_RemoveAttribute", elementRef, attributeName )
      : false;

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

public static string? GetStyleProperty(this ElementReference? elementRef,string propertyName) =>
   elementRef.HasValue ? UJS.Invoke<string?>(
      "Element_GetStyleProperty", elementRef, propertyName )
      : null;
public static bool SetStyleProperty( this ElementReference? elementRef,
                                     string propertyName, string? value ) =>
   elementRef.HasValue ? UJS.Invoke<bool>(
      "Element_SetStyleProperty", elementRef, propertyName, value )
      : false;
public static bool RemoveStyleProperty(this ElementReference? elementRef,string propertyName) =>
   elementRef.HasValue ? UJS.Invoke<bool>(
      "Element_RemoveStyleProperty", elementRef, propertyName )
      : false;

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

public static bool ContainsFocus(this ElementReference? elementRef) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_ContainsFocus", elementRef ) : false;
public static bool IsFocused(this ElementReference? elementRef) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_IsFocused", elementRef ) : false;

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

public static bool Click(this ElementReference? elementRef) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_Click", elementRef ) : false;

public static bool DeferredClick(this ElementReference? elementRef) =>
   DeferredClick( elementRef, 0 );
public static bool DeferredClick(this ElementReference? elementRef,int milliseconds) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_DeferredClick", elementRef ) : false;

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

public static bool Focus(this ElementReference? elementRef)
{
   if ( !elementRef.HasValue )
      return false;
   UJS.Invoke( "Element_Focus", elementRef );
   return true;
}
public static bool DeferredFocus(this ElementReference? elementRef) =>
   DeferredFocus( elementRef, 0 );
public static bool DeferredFocus(this ElementReference? elementRef,int milliseconds)
{
   if ( !elementRef.HasValue )
      return false;
   UJS.Invoke( "Element_DeferredFocus", elementRef, milliseconds );
   return true;
}

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

public static bool Select(this ElementReference? elementRef) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_Select", elementRef ) : false;
public static bool DeferredSelect(this ElementReference? elementRef) =>
   DeferredSelect( elementRef, 0 );
public static bool DeferredSelect(this ElementReference? elementRef,int milliseconds) =>
   elementRef.HasValue ? UJS.Invoke<bool>( "Element_DeferredSelect", elementRef ) : false;

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

public static bool FocusSelect(this ElementReference? elementRef)
{
   if ( !elementRef.HasValue )
      return false;
   UJS.Invoke( "Element_FocusSelect", elementRef );
   return true;
}
public static bool DeferredFocusSelect(this ElementReference? elementRef) =>
   DeferredFocusSelect( elementRef, 0 );
public static bool DeferredFocusSelect(this ElementReference? elementRef,int milliseconds)
{
   if ( !elementRef.HasValue )
      return false;
   UJS.Invoke( "Element_DeferredFocusSelect", elementRef, milliseconds );
   return true;
}

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

public static bool SelectAll(this ElementReference? containerRef) =>
   containerRef.HasValue ? UJS.Invoke<bool>( "Element_SelectAll", containerRef ) : false;

public static bool DeferredSelectAll(this ElementReference? containerRef) =>
   DeferredSelectAll( containerRef, 0 );
public static bool DeferredSelectAll(this ElementReference? containerRef,int milliseconds)
{
   if ( !containerRef.HasValue )
      return false;
   UJS.Invoke( "Element_DeferredSelectAll", containerRef, milliseconds );
   return true;
}

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

public static bool ScrollIntoView(this ElementReference? elementRef)
{
   if ( elementRef == null )
      return false;
   UJS.Invoke( "Element_ScrollIntoView", elementRef );
   return true;
}
public static bool DeferredScrollIntoView(this ElementReference? elementRef) =>
   DeferredScrollIntoView( elementRef, 0 );
public static bool DeferredScrollIntoView(this ElementReference? elementRef,int milliseconds)
{
   if ( elementRef == null )
      return false;
   UJS.Invoke( "Element_DeferredScrollIntoView", elementRef, milliseconds );
   return true;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // UHtmlElement
//**************************************************************************************************

} // AFXUI
