//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// TypeScript support for Blazor-WASM application | Author: Sergei Y.Kitaev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// App.configuration etc. (static class):
class App
{
   private static _IsDebugConfiguration_: boolean = false

   static IsDebugConfiguration(): boolean {
      return App._IsDebugConfiguration_
   }
   static IsReleaseConfiguration(): boolean {
      return !App.IsDebugConfiguration()
   }

   static SpecifyIsDebugConfiguration() {
      App._IsDebugConfiguration_ = true
   }

   static Window_OnFocus() {
      ServiceDialogFrame.HandleEarly_Window_OnFocus()
      WASM.Invoke('wasm_App_FocusChanged')
      WASM.AsyncInvoke('wasm_App_FocusChanged_A')
      ServiceDialogFrame.HandleLate_Window_OnFocus()
   }
   static Window_OnBlur() {
   // Deferred focus blur (because non-deferred one is impossible in .NET 5.0).
      setTimeout(()=>{ WASM.Invoke('wasm_App_FocusBlur') })
      setTimeout(()=>{ WASM.AsyncInvoke('wasm_App_FocusBlur_A') })
   }

   static Window_OnKeyDown(e: KeyboardEvent) {
      DotNet.invokeMethod(WASM.AssemblyName(), 'wasm_App_OnKeyDown',
         e.altKey, e.code, e.ctrlKey, e.key, e.location, e.metaKey, e.repeat, e.shiftKey, e.type )
      DotNet.invokeMethodAsync(WASM.AssemblyName(), 'wasm_App_OnKeyDown_A',
         e.altKey, e.code, e.ctrlKey, e.key, e.location, e.metaKey, e.repeat, e.shiftKey, e.type )
   }
   static Window_OnKeyUp(e: KeyboardEvent) {
      DotNet.invokeMethod(WASM.AssemblyName(), 'wasm_App_OnKeyUp',
         e.altKey, e.code, e.ctrlKey, e.key, e.location, e.metaKey, e.repeat, e.shiftKey, e.type )
      DotNet.invokeMethodAsync(WASM.AssemblyName(), 'wasm_App_OnKeyUp_A',
         e.altKey, e.code, e.ctrlKey, e.key, e.location, e.metaKey, e.repeat, e.shiftKey, e.type )
   }
/*
   static Window_OnInput() {
      let activeElement = HDoc.FocusedElement()
      var id: string|null = activeElement ? activeElement.id : null
      WASM.Invoke_1('wasm_App_OnInput',id)
      WASM.AsyncInvoke_1('wasm_App_OnInput_A',id).then(r => {})
   }
*/
} // App

//==================================================================================================
// APP.CONFIGURATION ETC. — FUNCTIONS:
//--------------------------------------------------------------------------------------------------

function App_SpecifyIsDebugConfiguration() {
   App.SpecifyIsDebugConfiguration()
}

function App_RegisterEvents() {
   window.addEventListener('focus', App.Window_OnFocus, true)
   window.addEventListener('blur', App.Window_OnBlur, true)
// window.addEventListener('input', App.Window_OnInput, true)
   window.addEventListener('keydown', App.Window_OnKeyDown, true)
   window.addEventListener('keyup', App.Window_OnKeyUp, true)
   //window.addEventListener('', App.Window_On..., true)
}

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