using System;
using System.Windows.Forms;

namespace TD.SandDock
{
	internal class g
	{
		public static ControlLayoutSystem a(SandDockManager A_0, DockLocation A_1, int A_2, Guid A_3, bool A_4)
		{
			DockContainer dockContainer = g.a(A_0, A_1);
			if (dockContainer == null)
			{
				throw new InvalidOperationException("No appropriate container could be found for the last fixed dock location recorded.");
			}
			foreach (object obj in dockContainer.c)
			{
				LayoutSystemBase layoutSystemBase = (LayoutSystemBase)obj;
				if (layoutSystemBase is ControlLayoutSystem && ((ControlLayoutSystem)layoutSystemBase).Guid == A_3)
				{
					return (ControlLayoutSystem)layoutSystemBase;
				}
			}
			ControlLayoutSystem controlLayoutSystem = A_4 ? new DocumentLayoutSystem() : new ControlLayoutSystem();
			if (A_2 < 0)
			{
				A_2 = 0;
			}
			else if (A_2 > dockContainer.LayoutSystem.LayoutSystems.Count)
			{
				A_2 = dockContainer.LayoutSystem.LayoutSystems.Count;
			}
			dockContainer.LayoutSystem.LayoutSystems.Insert(A_2, controlLayoutSystem);
			return controlLayoutSystem;
		}

		public static void a(Control A_0)
		{
			if (A_0.Parent == null)
			{
				return;
			}
			if (A_0.ContainsFocus)
			{
				A_0.Parent.Focus();
			}
			if (A_0 is DockControl)
			{
				((DockControl)A_0).IgnoreFontEvents = true;
			}
			A_0.Parent.Controls.Remove(A_0);
			if (A_0 is DockControl)
			{
				((DockControl)A_0).IgnoreFontEvents = false;
			}
		}

		public static void a(DockControl A_0)
		{
			if (A_0 == null)
			{
				throw new ArgumentNullException();
			}
			ControlLayoutSystem b = A_0.b;
			if (b == null)
			{
				return;
			}
			DockContainer dockContainer = b.DockContainer;
			bool containsFocus = A_0.ContainsFocus;
			b.Controls.Remove(A_0);
			if (b.Controls.Count == 0)
			{
				if (b.PopupContainer != null)
				{
					b.PopupContainer.b();
				}
				((SplitLayoutSystem)b.Parent).LayoutSystems.Remove(b);
				if (dockContainer.IsFloating && dockContainer.LayoutSystem.LayoutSystems.Count == 0)
				{
					dockContainer.Manager.a((m)dockContainer);
				}
			}
			if (containsFocus && dockContainer is DocumentContainer)
			{
				DocumentContainer documentContainer = (DocumentContainer)dockContainer;
				DockControl dockControl = documentContainer.TopMostDocument;
				if (dockControl != null)
				{
					dockControl.Activate();
				}
			}
		}

		public static DockContainer a(SandDockManager A_0, DockLocation A_1)
		{
			if (A_0 == null)
			{
				throw new ArgumentNullException();
			}
			switch (A_1)
			{
			case DockLocation.Left:
			{
				DockContainer dockContainer = A_0.a(DockStyle.Left);
				if (dockContainer == null)
				{
					throw new InvalidOperationException("No Left DockContainer found.");
				}
				return dockContainer;
			}
			case DockLocation.Right:
			{
				DockContainer dockContainer = A_0.a(DockStyle.Right);
				if (dockContainer == null)
				{
					throw new InvalidOperationException("No Right DockContainer found.");
				}
				return dockContainer;
			}
			case DockLocation.Top:
			{
				DockContainer dockContainer = A_0.a(DockStyle.Top);
				if (dockContainer == null)
				{
					throw new InvalidOperationException("No Top DockContainer found.");
				}
				return dockContainer;
			}
			case DockLocation.Bottom:
			{
				DockContainer dockContainer = A_0.a(DockStyle.Bottom);
				if (dockContainer == null)
				{
					throw new InvalidOperationException("No Bottom DockContainer found.");
				}
				return dockContainer;
			}
			case DockLocation.Float:
				if (A_0.a.Count == 0)
				{
					throw new InvalidOperationException("No containers found.");
				}
				return A_0.b();
			case DockLocation.Center:
			{
				DockContainer dockContainer = A_0.a(DockStyle.Fill);
				if (dockContainer == null)
				{
					throw new InvalidOperationException("No Fill DockContainer found.");
				}
				return dockContainer;
			}
			default:
				return null;
			}
		}
	}
}
