namespace VaioxOnline
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    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.Windows.Forms;

    internal class FlatListBox : Control
    {
        private string[] _items;
        [CompilerGenerated, DebuggerBrowsable(DebuggerBrowsableState.Never), AccessedThroughProperty("ListBx")]
        private ListBox _ListBx;
        private Color _SelectedColor;
        private Color BaseColor;

        public FlatListBox()
        {
            this.ListBx = new ListBox();
            this._items = new string[] { "" };
            this.BaseColor = Color.FromArgb(0x2d, 0x2f, 0x31);
            this._SelectedColor = Helpers._FlatColor;
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.ListBx.DrawMode = DrawMode.OwnerDrawFixed;
            this.ListBx.ScrollAlwaysVisible = false;
            this.ListBx.HorizontalScrollbar = false;
            this.ListBx.BorderStyle = BorderStyle.None;
            this.ListBx.BackColor = this.BaseColor;
            this.ListBx.ForeColor = Color.White;
            this.ListBx.Location = new Point(3, 3);
            this.ListBx.Font = new Font("Segoe UI", 8f);
            this.ListBx.ItemHeight = 20;
            this.ListBx.Items.Clear();
            this.ListBx.IntegralHeight = false;
            base.Size = new Size(0x83, 0x65);
            this.BackColor = this.BaseColor;
        }

        public void AddItem(object item)
        {
            this.ListBx.Items.Remove("");
            this.ListBx.Items.Add(RuntimeHelpers.GetObjectValue(item));
        }

        public void AddRange(object[] items)
        {
            this.ListBx.Items.Remove("");
            this.ListBx.Items.AddRange(items);
        }

        public void Clear()
        {
            this.ListBx.Items.Clear();
        }

        public void ClearSelected()
        {
            int num = this.ListBx.SelectedItems.Count - 1;
            for (int i = num; i >= 0; i += -1)
            {
                this.ListBx.Items.Remove(RuntimeHelpers.GetObjectValue(this.ListBx.SelectedItems[i]));
            }
        }

        public void Drawitem(object sender, DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();
                e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                if (Strings.InStr(e.State.ToString(), "Selected,", CompareMethod.Binary) > 0)
                {
                    e.Graphics.FillRectangle(new SolidBrush(this._SelectedColor), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
                    e.Graphics.DrawString(" " + this.ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8f), Brushes.White, (float) e.Bounds.X, (float) (e.Bounds.Y + 2));
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x33, 0x35, 0x37)), new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
                    e.Graphics.DrawString(" " + this.ListBx.Items[e.Index].ToString(), new Font("Segoe UI", 8f), Brushes.White, (float) e.Bounds.X, (float) (e.Bounds.Y + 2));
                }
                e.Graphics.Dispose();
            }
        }

        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            if (!base.Controls.Contains(this.ListBx))
            {
                base.Controls.Add(this.ListBx);
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Helpers.B = new Bitmap(base.Width, base.Height);
            Helpers.G = Graphics.FromImage(Helpers.B);
            Rectangle rect = new Rectangle(0, 0, base.Width, base.Height);
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            this.ListBx.Size = new Size(base.Width - 6, base.Height - 2);
            g.FillRectangle(new SolidBrush(this.BaseColor), rect);
            g = null;
            base.OnPaint(e);
            Helpers.G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0);
            Helpers.B.Dispose();
        }

        [Category("Options")]
        public string[] items
        {
            get => 
                this._items
            set
            {
                this._items = value;
                this.ListBx.Items.Clear();
                this.ListBx.Items.AddRange(value);
                base.Invalidate();
            }
        }

        private ListBox ListBx
        {
            [CompilerGenerated]
            get => 
                this._ListBx
            [MethodImpl(MethodImplOptions.Synchronized), CompilerGenerated]
            set
            {
                DrawItemEventHandler handler = new DrawItemEventHandler(this.Drawitem);
                ListBox box = this._ListBx;
                if (box != null)
                {
                    box.DrawItem -= handler;
                }
                this._ListBx = value;
                box = this._ListBx;
                if (box != null)
                {
                    box.DrawItem += handler;
                }
            }
        }

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

        public int SelectedIndex =>
            this.ListBx.SelectedIndex

        public string SelectedItem =>
            Conversions.ToString(this.ListBx.SelectedItem)
    }
}

