namespace VaioxOnline
{
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows.Forms;

    [DefaultEvent("CheckedChanged")]
    internal class FlatToggle : Control
    {
        private bool _Checked = false;
        private Color BaseColor = Helpers._FlatColor;
        private Color BaseColorRed = Color.FromArgb(220, 0x55, 0x60);
        private Color BGColor = Color.FromArgb(0x54, 0x55, 0x56);
        private int H;
        private _Options O;
        private MouseState State = MouseState.None;
        private Color TextColor = Color.FromArgb(0xf3, 0xf3, 0xf3);
        private Color ToggleColor = Color.FromArgb(0x2d, 0x2f, 0x31);
        private int W;

        [field: CompilerGenerated, DebuggerBrowsable(0)]
        public event CheckedChangedEventHandler CheckedChanged;

        public FlatToggle()
        {
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.BackColor = Color.Transparent;
            base.Size = new Size(0x2c, base.Height + 1);
            this.Cursor = Cursors.Hand;
            this.Font = new Font("Segoe UI", 10f);
            base.Size = new Size(0x4c, 0x21);
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            this._Checked = !this._Checked;
            CheckedChangedEventHandler checkedChangedEvent = this.CheckedChangedEvent;
            if (checkedChangedEvent != null)
            {
                checkedChangedEvent(this);
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            this.State = MouseState.Down;
            base.Invalidate();
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            this.State = MouseState.Over;
            base.Invalidate();
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this.State = MouseState.None;
            base.Invalidate();
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            this.State = MouseState.Over;
            base.Invalidate();
        }

        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;
            GraphicsPath path = new GraphicsPath();
            GraphicsPath path2 = new GraphicsPath();
            Rectangle rectangle = new Rectangle(0, 0, this.W, this.H);
            Rectangle rectangle2 = new Rectangle(this.W / 2, 0, 0x26, this.H);
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            switch (this.O)
            {
                case _Options.Style1:
                    path = Helpers.RoundRec(rectangle, 6);
                    path2 = Helpers.RoundRec(rectangle2, 6);
                    g.FillPath(new SolidBrush(this.BGColor), path);
                    g.FillPath(new SolidBrush(this.ToggleColor), path2);
                    g.DrawString("OFF", this.Font, new SolidBrush(this.BGColor), new Rectangle(0x13, 1, this.W, this.H), Helpers.CenterSF);
                    if (this.Checked)
                    {
                        path = Helpers.RoundRec(rectangle, 6);
                        path2 = Helpers.RoundRec(new Rectangle(this.W / 2, 0, 0x26, this.H), 6);
                        g.FillPath(new SolidBrush(this.ToggleColor), path);
                        g.FillPath(new SolidBrush(this.BaseColor), path2);
                        g.DrawString("ON", this.Font, new SolidBrush(this.BaseColor), new Rectangle(8, 7, this.W, this.H), Helpers.NearSF);
                    }
                    break;

                case _Options.Style2:
                    path = Helpers.RoundRec(rectangle, 6);
                    rectangle2 = new Rectangle(4, 4, 0x24, this.H - 8);
                    path2 = Helpers.RoundRec(rectangle2, 4);
                    g.FillPath(new SolidBrush(this.BaseColorRed), path);
                    g.FillPath(new SolidBrush(this.ToggleColor), path2);
                    g.DrawLine(new Pen(this.BGColor), 0x12, 20, 0x12, 12);
                    g.DrawLine(new Pen(this.BGColor), 0x16, 20, 0x16, 12);
                    g.DrawLine(new Pen(this.BGColor), 0x1a, 20, 0x1a, 12);
                    g.DrawString("r", new Font("Marlett", 8f), new SolidBrush(this.TextColor), new Rectangle(0x13, 2, base.Width, base.Height), Helpers.CenterSF);
                    if (this.Checked)
                    {
                        path = Helpers.RoundRec(rectangle, 6);
                        rectangle2 = new Rectangle((this.W / 2) - 2, 4, 0x24, this.H - 8);
                        path2 = Helpers.RoundRec(rectangle2, 4);
                        g.FillPath(new SolidBrush(this.BaseColor), path);
                        g.FillPath(new SolidBrush(this.ToggleColor), path2);
                        g.DrawLine(new Pen(this.BGColor), (this.W / 2) + 12, 20, (this.W / 2) + 12, 12);
                        g.DrawLine(new Pen(this.BGColor), (this.W / 2) + 0x10, 20, (this.W / 2) + 0x10, 12);
                        g.DrawLine(new Pen(this.BGColor), (this.W / 2) + 20, 20, (this.W / 2) + 20, 12);
                        g.DrawString("\x00fc", new Font("Wingdings", 14f), new SolidBrush(this.TextColor), new Rectangle(8, 7, base.Width, base.Height), Helpers.NearSF);
                    }
                    break;

                case _Options.Style3:
                    path = Helpers.RoundRec(rectangle, 0x10);
                    rectangle2 = new Rectangle(this.W - 0x1c, 4, 0x16, this.H - 8);
                    path2.AddEllipse(rectangle2);
                    g.FillPath(new SolidBrush(this.ToggleColor), path);
                    g.FillPath(new SolidBrush(this.BaseColorRed), path2);
                    g.DrawString("OFF", this.Font, new SolidBrush(this.BaseColorRed), new Rectangle(-12, 2, this.W, this.H), Helpers.CenterSF);
                    if (this.Checked)
                    {
                        path = Helpers.RoundRec(rectangle, 0x10);
                        rectangle2 = new Rectangle(6, 4, 0x16, this.H - 8);
                        path2.Reset();
                        path2.AddEllipse(rectangle2);
                        g.FillPath(new SolidBrush(this.ToggleColor), path);
                        g.FillPath(new SolidBrush(this.BaseColor), path2);
                        g.DrawString("ON", this.Font, new SolidBrush(this.BaseColor), new Rectangle(12, 2, this.W, this.H), Helpers.CenterSF);
                    }
                    break;

                case _Options.Style4:
                    if (this.Checked)
                    {
                    }
                    break;

                case _Options.Style5:
                    if (this.Checked)
                    {
                    }
                    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.Width = 0x4c;
            base.Height = 0x21;
        }

        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);
            base.Invalidate();
        }

        [Category("Options")]
        public bool Checked
        {
            get => 
                this._Checked
            set
            {
                this._Checked = value;
            }
        }

        [Category("Options")]
        public _Options Options
        {
            get => 
                this.O
            set
            {
                this.O = value;
            }
        }

        [Flags]
        public enum _Options
        {
            Style1,
            Style2,
            Style3,
            Style4,
            Style5
        }

        public delegate void CheckedChangedEventHandler(object sender);
    }
}

