using Hotline.Ai.Quality;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;

namespace Hotline.Pdf
{
    public class QuestPdfManager : IPdfManager
    {
        public void GeneratePdf(string title, string content, Stream stream) => CreateDocument(title, content).GeneratePdf(stream);

        public void GeneratePdf(string title, string content, string path) => CreateDocument(title, content).GeneratePdf(path);


        private Document CreateDocument(string title, string content)
        {
            return Document.Create(container =>
            {
                container.Page(page =>
                {
                    page.Size(PageSizes.A4);
                    page.Margin(2, Unit.Centimetre);
                    page.PageColor(Colors.White);
                    page.DefaultTextStyle(x => x.FontSize(20));

                    page.Header()
                        .Text(title)
                        .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);

                    page.Content()
                        .PaddingVertical(1, Unit.Centimetre)
                        .Column(x =>
                        {
                            x.Spacing(20);

                            //x.Item().Text(Placeholders.LoremIpsum());
                            //x.Item().Image(Placeholders.Image(200, 100));
                            x.Item().Text(content);
                        });

                    page.Footer()
                        .AlignCenter()
                        .Text(x =>
                        {
                            x.Span("Page ");
                            x.CurrentPageNumber();
                        });
                });
            });
        }
    }
}
