using ReportGeneration.Abstract;
using System.IO;
using System.Text;

namespace ReportGeneration.Generators;

internal class CollapsibleHtmlTableGenerator : HtmlTableGenerator
{
  public string DetailsClass { get; init; }
  public string Summary { get; init; } = "Show table";

  /// <inheritdoc />
  public CollapsibleHtmlTableGenerator(int columns)
    : base(columns) { }

  /// <inheritdoc />
  public CollapsibleHtmlTableGenerator(int columns, Stream stream)
    : base(columns, stream) { }

  /// <inheritdoc />
  public CollapsibleHtmlTableGenerator(int columns, Stream stream, Encoding encoding)
    : base(columns, stream, encoding) { }

  #region Overrides of HtmlTableGenerator

  /// <inheritdoc />
  protected override void OnOpen()
  {
    Writer.Write($"<details class=\"{DetailsClass}\" open>");
    Writer.Write(HtmlTools.Wrap("summary", Summary));
    base.OnOpen();
  }

  /// <inheritdoc />
  protected override void OnClose()
  {
    base.OnClose();
    Writer.Write($"</details>");
  }

  #endregion
}
