namespace VaioxOnline
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;
    using System.Windows.Forms;

    internal class FlatProgressBar : Control
    {
        private Color _BaseColor = Color.FromArgb(0x2d, 0x2f, 0x31);
        private Color _DarkerProgress = Color.FromArgb(0x17, 0x94, 0x5c);
        private int _Maximum = 100;
        private Color _ProgressColor = Helpers._FlatColor;
        private int _Value = 0;
        private int H;
        private int W;

        public FlatProgressBar()
        {
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.BackColor = Color.FromArgb(60, 70, 0x49);
            base.Height = 0x2a;
        }

        protected override void CreateHandle()
        {
            base.CreateHandle();
            base.Height = 0x2a;
        }

        public void Increment(int Amount)
        {
            this.Value += Amount;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Helpers.B = new Bitmap(base.Width, base.Height);
            Helpers.G = Graphics.FromImage(Helpers.B);
            this.W = base.Width - 1;
            this.H = base.Height - 1;
            Rectangle rect = new Rectangle(0, 0x18, this.W, this.H);
            GraphicsPath path = new GraphicsPath();
            GraphicsPath path2 = new GraphicsPath();
            GraphicsPath path3 = new GraphicsPath();
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            int num = (int) Math.Round((double) ((((double) this._Value) / ((double) this._Maximum)) * base.Width));
            switch (this.Value)
            {
                case 0:
                    g.FillRectangle(new SolidBrush(this._BaseColor), rect);
                    g.FillRectangle(new SolidBrush(this._ProgressColor), new Rectangle(0, 0x18, num - 1, this.H - 1));
                    break;

                case 100:
                    g.FillRectangle(new SolidBrush(this._BaseColor), rect);
                    g.FillRectangle(new SolidBrush(this._ProgressColor), new Rectangle(0, 0x18, num - 1, this.H - 1));
                    break;

                default:
                {
                    g.FillRectangle(new SolidBrush(this._BaseColor), rect);
                    path.AddRectangle(new Rectangle(0, 0x18, num - 1, this.H - 1));
                    g.FillPath(new SolidBrush(this._ProgressColor), path);
                    HatchBrush brush = new HatchBrush(HatchStyle.Plaid, this._DarkerProgress, this._ProgressColor);
                    g.FillRectangle(brush, new Rectangle(0, 0x18, num - 1, this.H - 1));
                    Rectangle rectangle = new Rectangle(num - 0x12, 0, 0x22, 0x10);
                    path2 = Helpers.RoundRec(rectangle, 4);
                    g.FillPath(new SolidBrush(this._BaseColor), path2);
                    path3 = Helpers.DrawArrow(num - 9, 0x10, true);
                    g.FillPath(new SolidBrush(this._BaseColor), path3);
                    g.DrawString(Conversions.ToString(this.Value), new Font("Segoe UI", 10f), new SolidBrush(this._ProgressColor), new Rectangle(num - 11, -2, this.W, this.H), Helpers.NearSF);
                    break;
                }
            }
            g = null;
            base.OnPaint(e);
            Helpers.G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0);
            Helpers.B.Dispose();
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            base.Height = 0x2a;
        }

        [Category("Colors")]
        public Color DarkerProgress
        {
            get => 
                this._DarkerProgress
            set
            {
                this._DarkerProgress = value;
            }
        }

        [Category("Control")]
        public int Maximum
        {
            get => 
                this._Maximum
            set
            {
                if (value < this._Value)
                {
                    this._Value = value;
                }
                this._Maximum = value;
                base.Invalidate();
            }
        }

        [Category("Colors")]
        public Color ProgressColor
        {
            get => 
                this._ProgressColor
            set
            {
                this._ProgressColor = value;
            }
        }

        [Category("Control")]
        public int Value
        {
            get
            {
                if (this._Value == 0)
                {
                    return 0;
                }
                return this._Value;
            }
            set
            {
                if (value > this._Maximum)
                {
                    value = this._Maximum;
                    base.Invalidate();
                }
                this._Value = value;
                base.Invalidate();
            }
        }
    }
}

