using OpenCvSharp;
using Point = System.Drawing.Point;

namespace CandyboxPlugin.Recipe
{
    public static class ErrorTextHelper
    {
        private static Font _font = new Font(FontFamily.GenericMonospace, 8);
        public static void DrawErrorText(Graphics g,Point point, EErrorReason errorReason)
        {
            string errorText = errorReason.ToString();

            var measured=g.MeasureString(errorText, _font);
            var mRect = new RectangleF(new PointF(point.X-measured.Width/2,point.Y), measured);
            g.FillRectangle(Brushes.Bisque,mRect);
            g.DrawRectangle(Pens.Coral,mRect.X,mRect.Y,mRect.Width,mRect.Height);
            g.DrawString(errorReason.ToString(),_font,Brushes.Black,mRect.X,mRect.Y);
        }

        public static void DrawErrorText(Mat mat,OpenCvSharp.Point point, EErrorReason errorReason)
        {
            string errorText = errorReason.ToString();
            Cv2.Rectangle(mat,point,new OpenCvSharp.Point(point.X+80,point.Y+20),OpaqueScalar(Scalar.Bisque),thickness:Cv2.FILLED);
            Cv2.Rectangle(mat,point,new OpenCvSharp.Point(point.X+80,point.Y+20),OpaqueScalar(Scalar.Coral));
            Cv2.PutText(mat,errorText,new OpenCvSharp.Point(point.X,point.Y+15),HersheyFonts.HersheySimplex,0.4,OpaqueScalar(Scalar.Black));
            
        }
        public static void DrawErrorText(Mat mat, OpenCvSharp.Point point, string errorReason)
        {
            string errorText = errorReason.ToString();
            Cv2.Rectangle(mat, point, new OpenCvSharp.Point(point.X + 80, point.Y + 20), OpaqueScalar(Scalar.Bisque), thickness: Cv2.FILLED);
            Cv2.Rectangle(mat, point, new OpenCvSharp.Point(point.X + 80, point.Y + 20), OpaqueScalar(Scalar.Coral));
            Cv2.PutText(mat, errorText, new OpenCvSharp.Point(point.X, point.Y + 15), HersheyFonts.HersheySimplex, 0.4, OpaqueScalar(Scalar.Black));

        }
        private static Scalar OpaqueScalar(Scalar scalar)
        {
            return new Scalar(scalar.Val0, scalar.Val1, scalar.Val2, 255);
        }
    }
}