using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using TD.SandDock.Rendering;

namespace TD.SandDock
{
	internal class e : j
	{
		private new class a : i
		{
			private new const int m_a = 93;

			private const int m_b = 93;

			private const int m_c = 16;

			private const int m_d = 64;

			private e m_e = null;

			private ControlLayoutSystem m_f = null;

			private Rectangle m_g = Rectangle.Empty;

			private DockSide m_h = DockSide.None;

			private bool m_i = false;

			private Bitmap m_j = null;

			private new DockContainer k = null;

			private DockStyle l = DockStyle.None;

			[DllImport("user32.dll")]
			private static extern bool SetWindowPos(HandleRef A_0, int A_1, int A_2, int A_3, int A_4, int A_5, int A_6);

			private a()
			{
				base.FormBorderStyle = FormBorderStyle.None;
				base.ShowInTaskbar = false;
				base.StartPosition = FormStartPosition.Manual;
				SetStyle(ControlStyles.AllPaintingInWmPaint, value: true);
				SetStyle(ControlStyles.DoubleBuffer, value: true);
				BackColor = Color.FromArgb(245, 238, 238);
				this.m_j = new Bitmap(93, 93, PixelFormat.Format32bppArgb);
			}

			public a(e A_0, Rectangle A_1, DockStyle A_2, DockContainer A_3)
				: this()
			{
				this.m_e = A_0;
				l = A_2;
				k = A_3;
				switch (A_2)
				{
				case DockStyle.Left:
				{
					ref Rectangle reference4 = ref this.m_g;
					reference4 = new Rectangle(A_1.X + 15, A_1.Y + A_1.Height / 2 - 46, 93, 93);
					break;
				}
				case DockStyle.Right:
				{
					ref Rectangle reference3 = ref this.m_g;
					reference3 = new Rectangle(A_1.Right - 93 - 15, A_1.Y + A_1.Height / 2 - 46, 93, 93);
					break;
				}
				case DockStyle.Top:
				{
					ref Rectangle reference2 = ref this.m_g;
					reference2 = new Rectangle(A_1.X + A_1.Width / 2 - 46, A_1.Y + 15, 93, 93);
					break;
				}
				case DockStyle.Bottom:
				{
					ref Rectangle reference = ref this.m_g;
					reference = new Rectangle(A_1.X + A_1.Width / 2 - 46, A_1.Bottom - 93 - 15, 93, 93);
					break;
				}
				}
				f();
			}

			public a(e A_0, ControlLayoutSystem A_1)
				: this()
			{
				this.m_e = A_0;
				this.m_f = A_1;
				k = A_1.DockContainer;
				ref Rectangle reference = ref this.m_g;
				reference = new Rectangle(A_1.DockContainer.PointToScreen(A_1.Bounds.Location), A_1.Bounds.Size);
				ref Rectangle reference2 = ref this.m_g;
				reference2 = new Rectangle(this.m_g.X + this.m_g.Width / 2 - 46, this.m_g.Y + this.m_g.Height / 2 - 46, 93, 93);
				f();
			}

			private void f()
			{
				using (Graphics graphics = Graphics.FromImage(this.m_j))
				{
					graphics.Clear(Color.Transparent);
					Color highlight = SystemColors.Highlight;
					Color color = RendererBase.InterpolateColors(highlight, Color.Transparent, 0.2f);
					if (this.m_f != null)
					{
						Point[] points = new Point[4]
						{
							new Point(46, 9),
							new Point(83, 46),
							new Point(46, 83),
							new Point(9, 46)
						};
						using (SolidBrush brush = new SolidBrush(BackColor))
						{
							graphics.FillPolygon(brush, points);
						}
						graphics.DrawPolygon(SystemPens.ControlDark, points);
					}
					if (l == DockStyle.None || l == DockStyle.Top)
					{
						a(graphics, (this.m_i && this.m_h == DockSide.Top) ? highlight : color);
					}
					if (l == DockStyle.None || l == DockStyle.Right)
					{
						b(graphics, (this.m_i && this.m_h == DockSide.Right) ? highlight : color);
					}
					if (l == DockStyle.None || l == DockStyle.Bottom)
					{
						c(graphics, (this.m_i && this.m_h == DockSide.Bottom) ? highlight : color);
					}
					if (l == DockStyle.None || l == DockStyle.Left)
					{
						d(graphics, (this.m_i && this.m_h == DockSide.Left) ? highlight : color);
					}
					if (l == DockStyle.None)
					{
						e(graphics, (this.m_i && this.m_h == DockSide.None) ? highlight : color);
					}
				}
				a(this.m_j, byte.MaxValue);
			}

			protected override void a(bool A_0)
			{
				if (A_0)
				{
					this.m_j.Dispose();
				}
				Dispose(A_0);
			}

			public b a(Point A_0)
			{
				Point a_ = PointToClient(A_0);
				b b2 = null;
				b2 = new b(TD.SandDock.j.c.d);
				b2.c = this.m_f;
				b2.b = k;
				if (a(d(), a_) && (l == DockStyle.None || l == DockStyle.Top))
				{
					b2.d = DockSide.Top;
				}
				else if (a(c(), a_) && (l == DockStyle.None || l == DockStyle.Right))
				{
					b2.d = DockSide.Right;
				}
				else if (a(b(), a_) && (l == DockStyle.None || l == DockStyle.Bottom))
				{
					b2.d = DockSide.Bottom;
				}
				else if (a(a(), a_) && (l == DockStyle.None || l == DockStyle.Left))
				{
					b2.d = DockSide.Left;
				}
				else if (a(e(), a_) && l == DockStyle.None)
				{
					b2.a = TD.SandDock.j.c.e;
					b2.d = DockSide.None;
				}
				else
				{
					b2.a = TD.SandDock.j.c.a;
				}
				if (l != 0)
				{
					if (b2.a != 0)
					{
						b2.a = TD.SandDock.j.c.f;
						b2.e = this.m_e.a(k, this.m_e.f());
					}
				}
				else
				{
					b2.e = this.m_e.a(this.m_f.DockContainer, this.m_f, b2.d);
				}
				bool flag = b2.a != TD.SandDock.j.c.a;
				DockSide dockSide = ((b2.a == TD.SandDock.j.c.a) ? this.m_h : b2.d);
				if (flag != this.m_i || dockSide != this.m_h)
				{
					this.m_i = flag;
					this.m_h = dockSide;
					f();
				}
				return b2;
			}

			private bool a(GraphicsPath A_0, Point A_1)
			{
				Region region = new Region(new Rectangle(0, 0, 93, 93));
				region.Exclude(new Rectangle(0, 0, 93, 93));
				region.Union(A_0);
				return region.IsVisible(A_1);
			}

			[SpecialName]
			private GraphicsPath e()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddEllipse(29, 29, 33, 33);
				return graphicsPath;
			}

			[SpecialName]
			private GraphicsPath d()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[10]
				{
					new Point(25, 19),
					new Point(44, 0),
					new Point(48, 0),
					new Point(67, 19),
					new Point(57, 29),
					new Point(56, 28),
					new Point(50, 25),
					new Point(42, 25),
					new Point(36, 28),
					new Point(35, 29)
				});
				return graphicsPath;
			}

			[SpecialName]
			private GraphicsPath c()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[10]
				{
					new Point(73, 25),
					new Point(92, 44),
					new Point(92, 48),
					new Point(73, 67),
					new Point(63, 57),
					new Point(64, 56),
					new Point(67, 50),
					new Point(67, 42),
					new Point(64, 36),
					new Point(63, 35)
				});
				return graphicsPath;
			}

			[SpecialName]
			private GraphicsPath b()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[10]
				{
					new Point(67, 73),
					new Point(48, 92),
					new Point(44, 92),
					new Point(25, 73),
					new Point(35, 63),
					new Point(36, 64),
					new Point(42, 67),
					new Point(50, 67),
					new Point(56, 64),
					new Point(57, 63)
				});
				return graphicsPath;
			}

			[SpecialName]
			private GraphicsPath a()
			{
				GraphicsPath graphicsPath = new GraphicsPath();
				graphicsPath.AddPolygon(new Point[10]
				{
					new Point(29, 57),
					new Point(19, 67),
					new Point(0, 48),
					new Point(0, 44),
					new Point(19, 25),
					new Point(29, 35),
					new Point(28, 36),
					new Point(25, 42),
					new Point(25, 50),
					new Point(28, 56)
				});
				return graphicsPath;
			}

			[SpecialName]
			public Rectangle i()
			{
				return this.m_g;
			}

			private void e(Graphics A_0, Color A_1)
			{
				Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
				RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(e()))
				{
					pathGradientBrush.CenterColor = A_1;
					pathGradientBrush.SurroundColors = new Color[1] { color };
					A_0.FillPath(pathGradientBrush, e());
				}
				SmoothingMode smoothingMode = A_0.SmoothingMode;
				A_0.SmoothingMode = SmoothingMode.AntiAlias;
				using (Pen pen = new Pen(RendererBase.InterpolateColors(A_1, Color.Black, 0.1f)))
				{
					A_0.DrawPath(pen, e());
				}
				A_0.SmoothingMode = smoothingMode;
				using (Pen pen2 = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawLine(pen2, 39, 53, 39, 39);
					A_0.DrawLine(pen2, 39, 39, 54, 39);
					A_0.DrawLine(pen2, 54, 39, 54, 53);
					A_0.DrawLine(pen2, 40, 54, 46, 54);
					A_0.DrawLine(pen2, 48, 54, 53, 54);
					A_0.DrawLine(pen2, 47, 53, 47, 51);
					A_0.DrawLine(pen2, 47, 51, 54, 51);
				}
				using SolidBrush brush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight));
				A_0.FillRectangle(brush, 40, 40, 14, 11);
				A_0.FillRectangle(brush, 40, 51, 7, 3);
			}

			private void d(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(a()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[5] { color2, color2, A_1, color, color };
					A_0.FillPath(pathGradientBrush, a());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 9, 39, 12, 14);
					A_0.DrawLine(pen, 13, 39, 13, 53);
					A_0.DrawLine(pen, 15, 46, 19, 46);
					A_0.DrawLine(pen, 16, 45, 16, 47);
					A_0.DrawLine(pen, 17, 44, 17, 48);
				}
				using SolidBrush brush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight));
				A_0.FillRectangle(brush, 10, 40, 3, 13);
			}

			private void c(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(b()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[5] { color2, color2, A_1, color, color };
					A_0.FillPath(pathGradientBrush, b());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 39, 71, 14, 12);
					A_0.DrawLine(pen, 39, 79, 53, 79);
					A_0.DrawLine(pen, 46, 73, 46, 77);
					A_0.DrawLine(pen, 44, 75, 48, 75);
					A_0.DrawLine(pen, 45, 76, 47, 76);
				}
				using SolidBrush brush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight));
				A_0.FillRectangle(brush, 40, 80, 13, 3);
			}

			private void b(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(c()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[9] { color, A_1, color2, color2, color, color, color, color, color };
					A_0.FillPath(pathGradientBrush, c());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 71, 39, 12, 14);
					A_0.DrawLine(pen, 79, 39, 79, 53);
					A_0.DrawLine(pen, 73, 46, 77, 46);
					A_0.DrawLine(pen, 75, 44, 75, 48);
					A_0.DrawLine(pen, 76, 45, 76, 47);
				}
				using SolidBrush brush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight));
				A_0.FillRectangle(brush, 80, 40, 3, 13);
			}

			private void a(Graphics A_0, Color A_1)
			{
				using (PathGradientBrush pathGradientBrush = new PathGradientBrush(d()))
				{
					pathGradientBrush.CenterColor = A_1;
					Color color = RendererBase.InterpolateColors(A_1, Color.White, 0.2f);
					Color color2 = RendererBase.InterpolateColors(A_1, Color.Black, 0.2f);
					pathGradientBrush.SurroundColors = new Color[5] { color, color, A_1, color2, color2 };
					A_0.FillPath(pathGradientBrush, d());
				}
				using (Pen pen = new Pen(Color.FromArgb(225, SystemColors.ControlLightLight)))
				{
					A_0.DrawRectangle(pen, 39, 9, 14, 12);
					A_0.DrawLine(pen, 39, 13, 53, 13);
					A_0.DrawLine(pen, 46, 15, 46, 19);
					A_0.DrawLine(pen, 44, 17, 48, 17);
					A_0.DrawLine(pen, 45, 16, 47, 16);
				}
				using SolidBrush brush = new SolidBrush(Color.FromArgb(130, SystemColors.ControlLightLight));
				A_0.FillRectangle(brush, 40, 10, 13, 3);
			}

			private void a(double A_0, double A_1)
			{
				this.m_e.c = true;
				int tickCount = Environment.TickCount;
				while (true)
				{
					int num = Environment.TickCount - tickCount;
					if (num > 200)
					{
						break;
					}
					double num2 = (double)num / 200.0;
					num2 = A_0 + (A_1 - A_0) * num2;
					if (!base.IsDisposed)
					{
						a(this.m_j, (byte)num2);
						Application.DoEvents();
						continue;
					}
					return;
				}
				this.m_e.c = false;
				if (!base.IsDisposed)
				{
					a(this.m_j, (byte)A_1);
				}
			}

			public void g()
			{
				a(255.0, 0.0);
				((Form)this).Hide();
			}

			public void j()
			{
				a(this.m_j, 0);
				h();
				a(0.0, 255.0);
			}

			public void h()
			{
				SetWindowPos(new HandleRef(this, base.Handle), -1, this.m_g.X, this.m_g.Y, this.m_g.Width, this.m_g.Height, 80);
			}
		}

		private new ControlLayoutSystem m_a = null;

		private new a m_b = null;

		private new bool c = false;

		private Rectangle m_d = Rectangle.Empty;

		private a m_e;

		private new a f;

		private new a g;

		private new a h;

		public e(SandDockManager A_0, DockContainer A_1, LayoutSystemBase A_2, DockControl A_3, Point A_4, DockingHints A_5, bool A_6)
			: base(A_0, A_1, A_2, A_3, A_4, A_5, A_6)
		{
			if (k() != null && k().OwnerForm != null)
			{
				d();
				e();
			}
		}

		private void e()
		{
			DockContainer dockContainer = null;
			dockContainer = k().a(DockStyle.Top, k().OwnerForm);
			if (dockContainer != null)
			{
				g = new a(this, this.m_d, DockStyle.Top, dockContainer);
			}
			dockContainer = k().a(DockStyle.Left, k().OwnerForm);
			if (dockContainer != null)
			{
				this.m_e = new a(this, this.m_d, DockStyle.Left, dockContainer);
			}
			dockContainer = k().a(DockStyle.Bottom, k().OwnerForm);
			if (dockContainer != null)
			{
				h = new a(this, this.m_d, DockStyle.Bottom, dockContainer);
			}
			dockContainer = k().a(DockStyle.Right, k().OwnerForm);
			if (dockContainer != null)
			{
				f = new a(this, this.m_d, DockStyle.Right, dockContainer);
			}
			if (g != null)
			{
				g.h();
			}
			if (this.m_e != null)
			{
				this.m_e.h();
			}
			if (h != null)
			{
				h.h();
			}
			if (f != null)
			{
				f.h();
			}
		}

		public static Rectangle a(SandDockManager A_0, bool A_1)
		{
			Rectangle rectangle = A_0.OwnerForm.ClientRectangle;
			DockContainer dockContainer = null;
			dockContainer = A_0.a(DockStyle.Left, A_0.OwnerForm);
			if (dockContainer != null)
			{
				rectangle = new Rectangle(dockContainer.Bounds.Right, rectangle.Y, rectangle.Width - dockContainer.Bounds.Right, rectangle.Height);
			}
			dockContainer = A_0.a(DockStyle.Right, A_0.OwnerForm);
			if (dockContainer != null)
			{
				rectangle.Width -= rectangle.Right - dockContainer.Bounds.Left;
			}
			dockContainer = A_0.a(DockStyle.Top, A_0.OwnerForm);
			if (dockContainer != null)
			{
				rectangle = new Rectangle(rectangle.X, dockContainer.Bounds.Bottom, rectangle.Width, rectangle.Height - dockContainer.Bounds.Bottom);
			}
			dockContainer = A_0.a(DockStyle.Bottom, A_0.OwnerForm);
			if (dockContainer != null)
			{
				rectangle.Height -= rectangle.Bottom - dockContainer.Bounds.Top;
			}
			rectangle = new Rectangle(A_0.OwnerForm.PointToScreen(rectangle.Location), rectangle.Size);
			if (rectangle.Width < 100 && A_1)
			{
				rectangle.Inflate((100 - rectangle.Width) / 2, 0);
			}
			if (rectangle.Height < 100 && A_1)
			{
				rectangle.Inflate(0, (100 - rectangle.Height) / 2);
			}
			return rectangle;
		}

		private void d()
		{
			this.m_d = a(k(), A_1: true);
		}

		protected override b b(Point A_0)
		{
			b A_ = null;
			if (!c)
			{
				ControlLayoutSystem controlLayoutSystem = a(A_0, out A_);
				if (controlLayoutSystem == f() && h() == null)
				{
					controlLayoutSystem = null;
				}
				if (controlLayoutSystem != this.m_a)
				{
					if (this.m_b != null)
					{
						this.m_b.g();
						if (this.m_b != null)
						{
							this.m_b.Dispose();
							this.m_b = null;
						}
					}
					this.m_a = controlLayoutSystem;
					if (this.m_a != null)
					{
						this.m_b = new a(this, this.m_a);
						this.m_b.j();
					}
				}
			}
			if (A_ != null && A_.a == TD.SandDock.j.c.a)
			{
				A_ = null;
			}
			if (this.m_b != null && this.m_b.i().Contains(A_0) && A_ == null)
			{
				A_ = this.m_b.a(A_0);
			}
			if (g != null && g.i().Contains(A_0) && A_ == null)
			{
				A_ = g.a(A_0);
			}
			if (h != null && h.i().Contains(A_0) && A_ == null)
			{
				A_ = h.a(A_0);
			}
			if (this.m_e != null && this.m_e.i().Contains(A_0) && A_ == null)
			{
				A_ = this.m_e.a(A_0);
			}
			if (f != null && f.i().Contains(A_0) && A_ == null)
			{
				A_ = f.a(A_0);
			}
			return A_;
		}

		private ControlLayoutSystem a(Point A_0, out b A_1)
		{
			A_1 = null;
			ControlLayoutSystem[] array = g();
			foreach (ControlLayoutSystem controlLayoutSystem in array)
			{
				Rectangle rectangle = new Rectangle(controlLayoutSystem.DockContainer.PointToScreen(controlLayoutSystem.Bounds.Location), controlLayoutSystem.Bounds.Size);
				if (rectangle.Contains(A_0))
				{
					A_1 = a(controlLayoutSystem.DockContainer, controlLayoutSystem, A_0, A_3: false);
					if (A_1.a == TD.SandDock.j.c.a)
					{
						return controlLayoutSystem;
					}
					return null;
				}
			}
			return null;
		}

		private void a(ref a A_0)
		{
			if (A_0 != null)
			{
				A_0.Visible = false;
				A_0.Dispose();
				A_0 = null;
			}
		}

		public override void b()
		{
			a(ref this.m_b);
			a(ref this.m_e);
			a(ref g);
			a(ref f);
			a(ref h);
			base.b();
		}
	}
}
