using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Xsl;
using System.Xml;

namespace EdTestEmulator.ViewModels
{
    public class DocumentWindowViewModel
    {
        public string Title { get; set; }   
        public string XmlString { get; set; }

        public string XlstPath { get; set; }

        public string Url => "file:///H:/ComparerSrc/Ed/GTDSAMPLE/gtd.html";

        public string HtmlResult {  get; set; } = @"
<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">
<html xmlns=""http://www.w3.org/1999/xhtml"" xmlns:catESAD_ru=""urn:customs.ru:RUCommonAggregateTypes:5.21.0"" xmlns:RUScat_ru=""urn:customs.ru:RUSCommonAggregateTypes:5.21.0"" xmlns:RUDECLcat=""urn:customs.ru:RUDeclCommonAggregateTypesCust:5.21.0"" xmlns:goom=""urn:customs.ru:Information:CustomsDocuments:GTDoutCustomsMark:5.21.0"" xmlns:nGTDr=""urn:customs.ru:Information:ExchangeDocuments:NotifGTDRegistration:5.21.0"">
  <head>
    <meta content=""text/html; charset=UTF-8"" http-equiv=""Content-Type"" />
    <title>Электронная копия декларации на товары и транзитной декларации. Внешний формат.</title>
    <style type=""text/css"">
              body {background: #CCCCCC; font-size: 9pt;}
              div.page {
              width: 210mm;
              margin: 10px auto;
              padding: 5mm 10mm;
              background: white;
              border: solid 1px black;
              page-break-before: always;
              }

              div.page_album {
              width: 297mm;
              margin: 10px auto;
              padding: 10mm;
              background: white;
              border: solid 1px black;
              page-break-before: always;
              }

              div.page.nobreak {
              page-break-before: avoid;
              }
              
              /*Стиль для удаления чёрной границы вокруг нарисованной ""страницы"" при печати*/
              @media print {div.page {border: none; margin: 0; padding: 0;}}
              div.goods {background: white;}
              .bordered {
              border: solid 1px black;
              padding-top: 4pt;
              padding-bottom: 4pt;
              font-family: Arial;
              font-size: 9pt;
              font-weight: bold;
              }
              .underlined {border-bottom: solid 0.8pt black;}
              p.NumberDate {font-weight: bold;}
              .graph {font-family: Arial; font-size: 7pt;}
              .graphColumn {font-family: Arial; font-size: 6.5pt;}
              .graphTitleIt {font-family: Arial; font-size: 7pt; font-style: italic;}
              .graphMain {font-family: Arial; font-size: 9pt; font-weight: bold; }
              .graphNum {font-family: Arial; font-size: 7pt; font-weight: bold;}
              .graphNo {font-size: 7pt; font-weight: bold;}
              h1{font-size: 12pt;}
              table.addInfo {border-collapse: collapse; vertical-align: top;}
              table.addInfo th {border: 1px solid black; background-color: LightGrey;}
              table.addInfo td {border: 1px solid black; vertical-align: top;}
              hr {border: 0; border-bottom: 1px solid black; margin: 0;}
              .tr {border-right: 1px solid black;}
              .tl {border-left: 1px solid black;}
              .tb {border-bottom: 1px solid black;}
              .tt {border-top: 1px solid black;}
              .br {border-right: 2px solid black;}
              .bl {border-left: 2px solid black;}
              .bb {border-bottom: 2px solid black;}
              .bt {border-top: 2px solid black;}
              .db {border-bottom: 1px dashed black;}
              .dl {border-left: 1px dashed black;}
              .number {
              text-align: center;
              color: black;
              font-size: 11pt;
              font-weight: bold;
              vertical-align: middle;
              }
                </style>
  </head>
  <body>
    <div class=""page nobreak"">
      <p>TECKADSKADHSLKDHADKJSHAKDSDDADSAD</p>
    </div>
  </body>
</html>


";

        public void ConvertToHtml()
        {
            XslCompiledTransform transform = new XslCompiledTransform();
            using (XmlReader reader = XmlReader.Create(new StringReader(File.ReadAllText(XlstPath))))
            {
                transform.Load(reader);
            }
            StringWriter results = new StringWriter();
            using (XmlReader reader = XmlReader.Create(new StringReader(XmlString)))
            {
                transform.Transform(reader, null, results);
            }
            HtmlResult = results.ToString();
        }
    }
}
