using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Text;

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;

using CommonHelpers;

namespace MyFlat {

//**************************************************************************************************
/// <summary>
/// HTML-helpers (Razor)
/// </summary>
public static class HTMLHelpers {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <summary>
/// Helper-script attachement (JavaScript) from “wwwroot\ts
/// </summary>
public static HtmlString IncludeHelperScripts(this IHtmlHelper html)
{
   var sb = new StringBuilder();
   void APPEND_SCRIPTS(params string[] baseNames)
   {
      foreach (string baseName in baseNames)
         sb.AppendLine( $"<script src=\"/ts/Helpers/{baseName}.js?v="+
                        $"{DateTime.Now.Ticks}\"></script>" );
   }
   APPEND_SCRIPTS(
      "HOps", "HObject", "HArgChecking",
      "HDoc", "HElement", "HById", "HHttp", "HAjax" );
   return new HtmlString( sb.ToString() );
}

/// <summary>
/// Forming of service reference header (navigation images)
/// </summary>
public static HtmlString CreatePageHeaderServiceRefs(this IHtmlHelper html)
{
   var sb = new StringBuilder( "<div class='serviceReferenceDIV'>" );
   sb.Append( ServiceHomeReferenceHTML );
   sb.Append( ServiceBottomReferenceHTML );
   sb.Append( "</div>" );
   return new HtmlString( sb.ToString() );
}
/// <summary>
/// Forming of service reference footer (navigation images)
/// </summary>
public static HtmlString CreatePageFooterServiceRefs(this IHtmlHelper html)
{
   var sb = new StringBuilder( "<div class='serviceReferenceDIV'>" );
   sb.Append( ServiceTopReferenceHTML );
   sb.Append( "</div>" );
   return new HtmlString( sb.ToString() );
}

/// <summary>
/// Conditional accentuation of text with bold font style
/// </summary>
/// <exception cref="ArgumentNullException" />
public static HtmlString BoldIf(this IHtmlHelper html,bool condition,string text)
{
   HArgChecking.VerifyNotNull( text );
   var sb = new StringBuilder();
   if ( condition ) sb.Append("<b>");
   sb.Append( text );
   if ( condition ) sb.Append("</b>");
   return new HtmlString( sb.ToString() );
}

//--------------------------------------------------------------------------------------------------
//public static HtmlString (this IHtmlHelper html)
//{
//   var sb = new StringBuilder();
//   sb.Append( );
//   return new HtmlString( sb.ToString() );
//}
//==================================================================================================

static readonly string
   ServiceHomeReferenceHTML = string.Format(
      "<span class=\"faint_text\">[</span>"+
      "<a href=\"/\" class=\"normal_text\" title=\"{0}&#xA;({1})\">&nbsp;&nbsp;&nbsp;"+
      "<span class=\"symbolic_bold_text\">&#x2302;</span>&nbsp;&nbsp;&nbsp;</a>"+
      "<span class=\"faint_text\">]</span>",
      HLocal.TEXT( "Home", "На лицевую" ),
      HLocal.TEXT( "Passage to main page", "Переход на основную страницу" ) ),
   ServiceTopReferenceHTML = string.Format(
      "<span class=\"faint_text\">[</span>"+
      "<a href=\"#top\" class=\"normal_text\" title=\"{0}\">&nbsp;&nbsp;&nbsp;"+
      "<span class=\"symbolic_bold_text\">&#x21D1;</span>&nbsp;&nbsp;&nbsp;</a>"+
      "<span class=\"faint_text\">]</span>",
      HLocal.TEXT( "To page top (scroll up)", "Наверх (прокрутка)" ) ),
   ServiceBottomReferenceHTML = string.Format(
      "<span class=\"faint_text\">[</span>"+
      "<a href=\"#bottom\" class=\"normal_text\" title=\"{0}\">&nbsp;&nbsp;&nbsp;"+
      "<span class=\"symbolic_bold_text\">&#x21D3;</span>&nbsp;&nbsp;&nbsp;</a>"+
      "<span class=\"faint_text\">]</span>",
      HLocal.TEXT( "To page bottom (scroll down)", "Вниз (прокрутка)" ) );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HTMLHelpers
//**************************************************************************************************

} // MyFlat
