using CefSharp;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;

namespace CefSharpWrap
{
    public class CefSharpWrapPdfExportSetting
    {
        [Description("Set to true to print headers and footers or false to not print headers and footers.")]
        public bool HeaderFooterEnabled { get; set; }

        [Description("Page title to display in the header. Only used if HeaderFooterEnabled is set to true.")]
        public string HeaderFooterTitle { get; set; }

        [Description("URL to display in the footer. Only used if HeaderFooterEnabled is set to true.")]
        public string HeaderFooterUrl { get; set; }

        public CefSharpWrapPdfExportMarginType MarginType { get; set; } = CefSharpWrapPdfExportMarginType.Minimum;

        [Description("Margin in millimeters. Only used if MarginType is set to Custom.")]
        public Margins Margin { get; set; } = new Margins();

        [Description("Output page size in microns. If either of these values is less than or equal to zero then the default paper size (A4) will be used.")]
        public Size PageSize { get; set; }

        [Description("Scale the PDF by the specified amount, defaults to 100%.")]
        public int ScaleFactor { get; set; }

        [Description("Set to true to print the selection only or false to print all.")]
        public bool SelectionOnly { get; set; }

        [Description("Set to true for landscape mode or false for portrait mode.")]
        public bool Landscape { get; set; }

        [Description("Set to true to print background graphics or false to not print background graphics.")]
        public bool BackgroundsEnabled { get; set; } = true;

        internal PdfPrintSettings ToCefSharpSetting()
        {
            return new PdfPrintSettings
            {
                SelectionOnly = SelectionOnly,
                Landscape = Landscape,
                BackgroundsEnabled = BackgroundsEnabled,

                HeaderFooterEnabled = HeaderFooterEnabled,
                HeaderFooterTitle = HeaderFooterTitle,
                HeaderFooterUrl = HeaderFooterUrl,

                ScaleFactor = ScaleFactor,

                MarginType = (CefPdfPrintMarginType)MarginType,
                MarginBottom = Margin.Bottom,
                MarginLeft = Margin.Left,
                MarginRight = Margin.Right,
                MarginTop = Margin.Top,

                PageHeight = PageSize.Height,
                PageWidth = PageSize.Width,
            };
        }
    }

    /// <summary>Margin type for PDF printing.</summary>
    public enum CefSharpWrapPdfExportMarginType
    {
        /// <summary>Default margins.</summary>
        Default,

        /// <summary>No margins.</summary>
        None,

        /// <summary>Minimum margins</summary>
        Minimum,

        /// <summary>Custom margins.</summary>
        Custom,
    }
}
