using Novacode;
using System.Drawing;

namespace Hotline.Share.Dtos.ExportWord
{
    public class ExportTable : IWordElement
    {
        /// <summary>
        /// 
        /// </summary>
        public List<ExportTableRow> Rows { get; set; } = new List<ExportTableRow>();

        /// <summary>
        /// 
        /// </summary>
        public int RowCount => Rows.Count;

        /// <summary>
        /// 
        /// </summary>
        public int ColumnCount { get; }

        /// <summary>
        /// 
        /// </summary>
        public List<(int, int, int)> MergeCellsInColumns { get; } = new List<(int, int, int)>();

        /// <summary>
        /// 
        /// </summary>
        public List<(int, int, int)> MergeCellsInRows { get; } = new List<(int, int, int)>();


        public ExportTable()
        {
        }

        public ExportTable(int rowCount, int columnCount)
        {
            ColumnCount = columnCount;
            for (int i = 0; i < rowCount; i++)
            {
                ExportTableRow fWTableRow = new ExportTableRow();
                for (int j = 0; j < columnCount; j++)
                {
                    ExportTableCell item = new ExportTableCell
                    {
                        Paragraphs = new List<ExportParagraph>
                    {
                        new ExportParagraph
                        {
                            Run = new ExportRun()
                        }
                    }
                    };
                    fWTableRow.Cells.Add(item);
                }

                Rows.Add(fWTableRow);
            }
        }

        public void MergeCellsInColumn(int columnIndex, int startRow, int endRow)
        {
            MergeCellsInColumns.Add((columnIndex, startRow, endRow));
        }

        public void MergeCellsInRow(int rowIndex, int startColumn, int endColumn)
        {
            MergeCellsInRows.Add((rowIndex, startColumn, endColumn));
        }
    }

    public class ExportTableCell
    {
        /// <summary>
        /// 
        /// </summary>
        public List<ExportParagraph> Paragraphs { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public double Width { get; set; } = 200.0;

        /// <summary>
        /// 
        /// </summary>
        public Color FillColor { get; set; } = Color.Empty;

        /// <summary>
        /// 
        /// </summary>
        public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;

    }

    public class ExportTableRow
    {
        /// <summary>
        /// 
        /// </summary>
        public List<ExportTableCell> Cells { get; set; } = new List<ExportTableCell>();

        /// <summary>
        /// 
        /// </summary>
        public double Height { get; set; }
    }

    public class ExportText : IWordElement
    {
        /// <summary>
        /// 
        /// </summary>
        public string Data { get; set; }
    }
}
