using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Net.Http;
using System.Diagnostics;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.Web;

using CommonHelpers.WASM;
using AFXUI;

using BookRegistry.Client.Shared;
using BookRegistry.Client.Components;
using BookRegistry.Client.DB;

namespace BookRegistry.Client.Pages {

//**************************************************************************************************
public partial class ErrorPage: APageComponent {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//==================================================================================================
#nullable disable
#nullable restore
//==================================================================================================
/*
protected ElementReference?
;
*/
string? ErrorMessageHtml;
MarkupString? ExceptionMarkup;

string? ExceptionCause => UBreakdown.ExceptionCause;
bool IsExceptionError => UBreakdown.Exception != null;
bool HasError => UBreakdown.HasErrorInfo;

string ExceptionMarkupClass =>
   Program.IsDebugConfiguration ? "pg_error_ExceptionTextWithStack" : "pg_error_ExceptionText";

string ForgetErrorTitle =>
   "Reset last error info …\n(That will cause navigation to home-page after reset.)";

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

protected override void OnInitialized() =>
go(()=>{
   base.OnInitialized();
   if ( UBreakdown.ErrorMessage != null )
      ErrorMessageHtml = UMarkup.ProvideWithEscapes( UBreakdown.ErrorMessage );
   ExceptionMarkup = (MarkupString)(UBreakdown.ExceptionHtml ?? "");
   UMagistral.DeferredInitiateReloadPage();
});

protected override void On_Load() =>
go(()=>{
   ErrorMI.ApplyToUI();
   DeferredFocusBackground = true;
   UBreakdown.NotifyErrorShown();
});
/*
protected override void On_AutoFocus() =>
go(()=>{
});
*/
//==================================================================================================

void ButtonForgetError_OnClick() =>
GO(()=>{
   UBreakdown.ResetErrorInfo();
   ErrorMI.ApplyToUI();
   NAV.NavigateTo( "/" );
});

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // ErrorPage
//**************************************************************************************************

} // BookRegistry.Client.Pages
