using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Text;
using FastReport;
using FastReport.Utils;
using FastReport.Export;
using System.Drawing;
using System.Drawing.Imaging;

namespace FastReport.Web.Blazor.Export
{
    public partial class BlazorExport
    {

        private static string HTMLColor(in Color color)
        {
            return ColorTranslator.ToHtml(color);
        }

        private static void SaveJpeg(Image image, Stream buff, int quality)
        {
            ImageCodecInfo ici = GetCodec("image/jpeg");
            EncoderParameters ep = new EncoderParameters();
            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            image.Save(buff, ici, ep);
        }

        private static ImageCodecInfo? GetCodec(string codec)
        {
            foreach (ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
            {
                if (ice.MimeType == codec)
                    return ice;
            }
            return null;
        }

        private string Px(double pixel)
        {
            return ExportUtils.FloatToString(pixel);
        }

        private string PxClosed(double pixel)
        {
            return Px(pixel) + "px;";
        }

    }
}
