using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
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 AboutPage: APageComponent {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

protected readonly string
   BlockTitle_Internals =
      "WASM-client internals, code packing (client/server) etc",
   BlockTitle_AtServerSide =
      "At server-side",
   BlockTitle_InsideDatabase =
      "Inside database (enhanced SQL-code as “soft-paft” of Web-service)",
   BlockTitle_Resume =
      "Resume";

//==================================================================================================
/*
protected override void OnInitialized() =>
go(()=>{
   base.OnInitialized();
});
*/
protected override void On_Load() =>
go(()=>{
   AboutMI.ApplyToUI();
   DeferredFocusBackground = true;
});
/*
protected override void On_AutoFocus() =>
go(()=>{
});
*/
//==================================================================================================

void UnhandledExceptionButton_OnClick() =>
GO(()=>{
   try {
      throw new ApplicationException( "Test error #1 has been thrown." );
   }
   catch (Exception e) {
      throw new ApplicationException( "Test error #2 has been thrown.", e );
   }
});

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

/// <exception cref="ArgumentException" />
static MarkupString BlockTitleHRef( string blockNoStr, string id,
                                    string href, string caption,
                                    string? upperBlockId=null,
                                    string? lowerBlockId=null ) =>
   BlockTitleHRef( blockNoStr, null, id, href, caption, upperBlockId, lowerBlockId );
/// <exception cref="ArgumentException" />
static MarkupString BlockTitleHRef( string blockNoStr, int? subTitleLevel,
                                    string id, string href, string caption,
                                    string? upperBlockId=null,
                                    string? lowerBlockId=null )
{
   var sb = new StringBuilder();
   int stl = subTitleLevel ?? -1;
   if ( !HOps.IsBetween( stl, -1, 2 ) )
      throw new ArgumentException(
         $"Incorrect value for block-title sublevel: {subTitleLevel}.",
         nameof(subTitleLevel) );
   string
      blockTitleNumberClass = stl==0 ? "page_BlockTitleNumberSPAN"
         : stl==1 ? "page_BlockSubTitleNumberSPAN_1"
         : stl==2 ? "page_BlockSubTitleNumberSPAN_2"
         : "page_BlockSubTitleNumberSPAN_1",
      blockTitleHRefClass = stl==0 ? "page_BlockTitleA"
         : stl==1 ? "page_BlockSubTitleA_1"
         : stl==2 ? "page_BlockSubTitleA_2"
         : "page_BlockSubTitleA_1";
   sb.Append( "<p class=\"bigSpacingP\">" );
   sb.Append($"<span class=\"{blockTitleNumberClass}\">{blockNoStr}</span>" );
   sb.Append( "&nbsp;" );
   sb.Append($"<a id=\"{id}\" class=\"{blockTitleHRefClass}\" href=\"{href}\" " );
   sb.Append( "title=\"Sctoll-to (up-align)\" " );
   sb.Append($"onclick=\"return HRef_ScrollToId('{id}')\">" );
   sb.Append( caption );
   sb.Append( "</a>" );
   sb.Append( "<br>" );
   if ( upperBlockId != null )
   {
      sb.Append( "<span class=\"symbolic_faint_text\">[</span>" );
      sb.Append( "<a href=\"#to_upper_block\" title=\"Scroll to upper block\" tabindex=\"-1\" " );
      sb.Append($"onfocus=\"HRef_EscapeFocus('{id}')\"" );
      sb.Append($"onclick=\"return HRef_DeferredScrollToId('{upperBlockId}')\">&nbsp;&nbsp;&nbsp;" );
      sb.Append( "<span class=\"symbolic_bold_text\">&#x21E1;</span>&nbsp;&nbsp;&nbsp;</a>" );
      sb.Append( "<span class=\"symbolic_faint_text\">]</span>" );
   }
   else
   {
      sb.Append( "<span class=\"symbolic_faint_text\">[</span>" );
      sb.Append( "<a href=\"#to_page_top\" title=\"Scroll to page-top\" tabindex=\"-1\" " );
      sb.Append( "onfocus=\"HRef_EscapeFocus()\"" );
      sb.Append( "onclick=\"return HRef_DeferredScrollToPageTop()\">&nbsp;&nbsp;&nbsp;" );
      sb.Append( "<span class=\"symbolic_text\">&#x21D1;</span>&nbsp;&nbsp;&nbsp;</a>" );
      sb.Append( "<span class=\"symbolic_faint_text\">]</span>" );
   }
   if ( lowerBlockId != null )
   {
      sb.Append( "<span class=\"symbolic_faint_text\">[</span>" );
      sb.Append( "<a href=\"#to_lower_block\" title=\"Scroll to lower block\" tabindex=\"-1\" " );
      sb.Append($"onfocus=\"HRef_EscapeFocus('{id}')\"" );
      sb.Append($"onclick=\"return HRef_DeferredScrollToId('{lowerBlockId}')\">&nbsp;&nbsp;&nbsp;" );
      sb.Append( "<span class=\"symbolic_bold_text\">&#x21E3;</span>&nbsp;&nbsp;&nbsp;</a>" );
      sb.Append( "<span class=\"symbolic_faint_text\">]</span>" );
   }
   else
   {
      sb.Append( "<span class=\"symbolic_faint_text\">[</span>" );
      sb.Append( "<a href=\"#to_page_bottom\" title=\"Scroll to page-bottom\" tabindex=\"-1\" " );
      sb.Append( "onfocus=\"HRef_EscapeFocus()\"" );
      sb.Append( "onclick=\"return HRef_DeferredScrollToPageBottom()\">&nbsp;&nbsp;&nbsp;" );
      sb.Append( "<span class=\"symbolic_text\">&#x21D3;</span>&nbsp;&nbsp;&nbsp;</a>" );
      sb.Append( "<span class=\"symbolic_faint_text\">]</span>" );
   }
   sb.Append( "</p>" );
   return (MarkupString)sb.ToString();
}

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

static MarkupString PropertyTR(string name,string? value,bool boldValue=false)
{
   var sb = new StringBuilder();
   sb.Append( "<tr>" );
   sb.Append( "<td class=\"propertyNameTD\">" );
   sb.Append( name );
   sb.Append( "</td>" );
   sb.Append( "<td class=\"propertySeparatorTD\"></td>" );
   sb.Append( "<td class=\"propertyValueTD\">" );
   if ( boldValue )
      sb.Append( "<b>" );
   if ( value != null )
      sb.Append( value );
   if ( boldValue )
      sb.Append( "</b>" );
   sb.Append( "</td>" );
   sb.AppendLine( "</tr>" );
   return (MarkupString)sb.ToString();
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // AboutPage
//**************************************************************************************************

} // BookRegistry.Client.Pages
