namespace VaioxOnline
{
    using System;
    using System.Collections;
    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 RadioButton : Control
    {
        private Color _BaseColor = Color.FromArgb(0x2d, 0x2f, 0x31);
        private Color _BorderColor = Helpers._FlatColor;
        private bool _Checked;
        private Color _TextColor = Color.FromArgb(0xf3, 0xf3, 0xf3);
        private int H;
        private _Options O;
        private MouseState State = MouseState.None;
        private int W;

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

        public RadioButton()
        {
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.Cursor = Cursors.Hand;
            base.Size = new Size(100, 0x16);
            this.BackColor = Color.FromArgb(60, 70, 0x49);
            this.Font = new Font("Segoe UI", 10f);
        }

        private void InvalidateControls()
        {
            if (base.IsHandleCreated && this._Checked)
            {
                IEnumerator enumerator;
                try
                {
                    enumerator = base.Parent.Controls.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Control current = (Control) enumerator.Current;
                        if ((current != this) && (current is VaioxOnline.RadioButton))
                        {
                            ((VaioxOnline.RadioButton) current).Checked = false;
                            base.Invalidate();
                        }
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
        }

        protected override void OnClick(EventArgs e)
        {
            if (!this._Checked)
            {
                this.Checked = true;
            }
            base.OnClick(e);
        }

        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            this.InvalidateControls();
        }

        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;
            Rectangle rect = new Rectangle(0, 2, base.Height - 5, base.Height - 5);
            Rectangle rectangle2 = new Rectangle(4, 6, this.H - 12, this.H - 12);
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            switch (this.O)
            {
                case _Options.Style1:
                    g.FillEllipse(new SolidBrush(this._BaseColor), rect);
                    switch (this.State)
                    {
                        case MouseState.Over:
                            g.DrawEllipse(new Pen(this._BorderColor), rect);
                            goto Label_010A;

                        case MouseState.Down:
                            g.DrawEllipse(new Pen(this._BorderColor), rect);
                            goto Label_010A;
                    }
                    break;

                case _Options.Style2:
                    g.FillEllipse(new SolidBrush(this._BaseColor), rect);
                    switch (this.State)
                    {
                        case MouseState.Over:
                            g.DrawEllipse(new Pen(this._BorderColor), rect);
                            g.FillEllipse(new SolidBrush(Color.FromArgb(0x76, 0xd5, 170)), rect);
                            break;

                        case MouseState.Down:
                            g.DrawEllipse(new Pen(this._BorderColor), rect);
                            g.FillEllipse(new SolidBrush(Color.FromArgb(0x76, 0xd5, 170)), rect);
                            break;
                    }
                    if (this.Checked)
                    {
                        g.FillEllipse(new SolidBrush(this._BorderColor), rectangle2);
                    }
                    goto Label_01E8;

                default:
                    goto Label_01E8;
            }
        Label_010A:
            if (this.Checked)
            {
                g.FillEllipse(new SolidBrush(this._BorderColor), rectangle2);
            }
        Label_01E8:
            g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), new Rectangle(20, 2, this.W, this.H), Helpers.NearSF);
            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 = 0x16;
        }

        public bool Checked
        {
            get => 
                this._Checked
            set
            {
                this._Checked = value;
                this.InvalidateControls();
                CheckedChangedEventHandler checkedChangedEvent = this.CheckedChangedEvent;
                if (checkedChangedEvent != null)
                {
                    checkedChangedEvent(this);
                }
                base.Invalidate();
            }
        }

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

        [Flags]
        public enum _Options
        {
            Style1,
            Style2
        }

        public delegate void CheckedChangedEventHandler(object sender);
    }
}

