// /************************************************************************
// * @file         MarkDownToHtmlConverter.cs
// * @author   Su Liang
// * @date       2023/04/14
// *
// * @copyright &copy Sicentury Inc.
// *
// * @brief
// *
// * @details
// *
// *
// * *****************************************************************************/

using System;
using System.Globalization;
using System.Text;
using System.Windows.Data;

namespace MECF.Framework.UI.Core.Converters
{
    public class MarkdownToHtmlConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string mdText)
            {
                var conv = new MarkdownDeep.Markdown();
                var html = conv.Transform(mdText);
                var sb = new StringBuilder();
                sb.Append(
                    "<!DOCTYPE html><html lang=\"en\">" +
                    "<head> " +
                    " <meta charset=\"UTF-8\" />" +
                    " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /> " +
                    " <title>Sic 系统更新历史记录</title> " +
                    " <style> " +
                    "  .mainContainer { font-family: Tahoma, Verdana, sans-serif;  margin: 10px;} " +
                    " </style>" +
                    " </head><body oncontextmenu=\"return false;\"> " +
                    " <div class=mainContainer> ");
                sb.Append(html);
                sb.Append("<div>" +
                          "</body>" +
                          "</html>");
                return sb.ToString();
            }
            else
            {
                return "<h1>Content is not Markdown text<h1>";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}