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 FormSkin : ContainerControl
    {
        private Color _BaseColor;
        private Color _BaseLight;
        private Color _BorderColor;
        private Color _HeaderColor;
        private Color _HeaderLight;
        private bool _HeaderMaximize;
        private bool Cap;
        private int H;
        private Point MousePoint;
        private object MoveHeight;
        private Color TextColor;
        public Color TextLight;
        private int W;

        public FormSkin()
        {
            base.MouseDoubleClick += new MouseEventHandler(this.FormSkin_MouseDoubleClick);
            this.Cap = false;
            this._HeaderMaximize = false;
            this.MousePoint = new Point(0, 0);
            this.MoveHeight = 50;
            this._HeaderColor = Color.FromArgb(0x2d, 0x2f, 0x31);
            this._BaseColor = Color.FromArgb(60, 70, 0x49);
            this._BorderColor = Color.FromArgb(0x35, 0x3a, 60);
            this.TextColor = Color.FromArgb(0xea, 0xea, 0xea);
            this._HeaderLight = Color.FromArgb(0xab, 0xab, 0xac);
            this._BaseLight = Color.FromArgb(0xc4, 0xc7, 200);
            this.TextLight = Color.FromArgb(0x2d, 0x2f, 0x31);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.BackColor = Color.White;
            this.Font = new Font("Segoe UI", 12f);
        }

        private void FormSkin_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.HeaderMaximize)
            {
                Rectangle rectangle = new Rectangle(0, 0, base.Width, Conversions.ToInteger(this.MoveHeight));
                if ((e.Button == MouseButtons.Left) & rectangle.Contains(e.Location))
                {
                    if (base.FindForm().WindowState == FormWindowState.Normal)
                    {
                        base.FindForm().WindowState = FormWindowState.Maximized;
                        base.FindForm().Refresh();
                    }
                    else if (base.FindForm().WindowState == FormWindowState.Maximized)
                    {
                        base.FindForm().WindowState = FormWindowState.Normal;
                        base.FindForm().Refresh();
                    }
                }
            }
        }

        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            base.ParentForm.FormBorderStyle = FormBorderStyle.None;
            base.ParentForm.AllowTransparency = false;
            base.ParentForm.TransparencyKey = Color.Fuchsia;
            base.ParentForm.FindForm().StartPosition = FormStartPosition.CenterScreen;
            this.Dock = DockStyle.Fill;
            base.Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            Rectangle rectangle = new Rectangle(0, 0, base.Width, Conversions.ToInteger(this.MoveHeight));
            if ((e.Button == MouseButtons.Left) & rectangle.Contains(e.Location))
            {
                this.Cap = true;
                this.MousePoint = e.Location;
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (this.Cap)
            {
                base.Parent.Location = Control.MousePosition - ((Size) this.MousePoint);
            }
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            this.Cap = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Helpers.B = new Bitmap(base.Width, base.Height);
            Helpers.G = Graphics.FromImage(Helpers.B);
            this.W = base.Width;
            this.H = base.Height;
            Rectangle rect = new Rectangle(0, 0, this.W, this.H);
            Rectangle rectangle2 = new Rectangle(0, 0, this.W, 50);
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            g.FillRectangle(new SolidBrush(this._BaseColor), rect);
            g.FillRectangle(new SolidBrush(this._HeaderColor), rectangle2);
            g.FillRectangle(new SolidBrush(Color.FromArgb(0xf3, 0xf3, 0xf3)), new Rectangle(8, 0x10, 4, 0x12));
            g.FillRectangle(new SolidBrush(Helpers._FlatColor), 0x10, 0x10, 4, 0x12);
            g.DrawString(this.Text, this.Font, new SolidBrush(this.TextColor), new Rectangle(0x1a, 15, this.W, this.H), Helpers.NearSF);
            g.DrawRectangle(new Pen(this._BorderColor), 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("Colors")]
        public Color BaseColor
        {
            get => 
                this._BaseColor
            set
            {
                this._BaseColor = value;
            }
        }

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

        [Category("Colors")]
        public Color FlatColor
        {
            get => 
                Helpers._FlatColor
            set
            {
                Helpers._FlatColor = value;
            }
        }

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

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

