@using System.IO
@using System.Drawing
@inherits DialogBaseComponent<PictureBoxControl>

<div style="@GetStyle"></div>

@code {

    protected override string GetStyle
        => $"{GetControlPosition()} {GetControlAlign()} {GetPictureBoxURL(Control.Image)} padding:0;margin:0;";

    protected string GetPictureBoxURL(Image image)
    {
        int hash = image.GetHashCode();
        if (!WebReport.PictureCache.ContainsKey(hash.ToString()))
        {
            using (MemoryStream picStream = new MemoryStream())
            {
                image.Save(picStream, image.RawFormat);
                byte[] imageArray = new byte[picStream.Length];
                picStream.Position = 0;
                picStream.Read(imageArray, 0, (int)picStream.Length);
                WebReport.PictureCache.Add(hash.ToString(), imageArray);
            }
        }

        string url = WebUtils.ToUrl(WebReport.template_ROUTE_BASE_PATH, $"preview.getPicture?");
        return $"background: url('{url}reportId={WebReport.ID}&pictureId={hash}') no-repeat !important;-webkit-print-color-adjust:exact;";
    }

}
