using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace BettingPredictor.UI
{
    /// <summary>
    /// ProgressBar moderna con stile piatto e bordi arrotondati
    /// </summary>
    internal class ModernProgressBar : ProgressBar
    {
        public Color BarColor { get; set; } = ModernTheme.PrimaryColor;
        public Color TrackColor { get; set; } = Color.FromArgb(49, 50, 68);

        public ModernProgressBar()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.Opaque, true);
            Height = 8;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            var g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            // Pulisci sfondo
            using (var bgBrush = new SolidBrush(Parent?.BackColor ?? ModernTheme.ContentBackground))
                g.FillRectangle(bgBrush, ClientRectangle);

            var rect = new Rectangle(0, 0, Width - 1, Height - 1);
            using (var path = ModernTheme.GetRoundedRectPath(rect, Height / 2))
            using (var brush = new SolidBrush(TrackColor))
            {
                g.FillPath(brush, path);
            }

            if (Maximum > Minimum && Value > Minimum)
            {
                float fraction = (float)(Value - Minimum) / (Maximum - Minimum);
                int fillWidth = (int)(rect.Width * fraction);
                if (fillWidth > 4)
                {
                    var fillRect = new Rectangle(0, 0, fillWidth, Height - 1);
                    using (var path = ModernTheme.GetRoundedRectPath(fillRect, Height / 2))
                    using (var brush = new LinearGradientBrush(fillRect, BarColor, ControlPaint.Light(BarColor, 0.3f), LinearGradientMode.Horizontal))
                    {
                        g.FillPath(brush, path);
                    }
                }
            }
        }
    }
}
