using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;

namespace TD.SandDock
{
	internal class DocumentContainerDesigner : DockContainerDesigner
	{
		private new DesignerVerbCollection m_a = null;

		private new DocumentContainer b = null;

		public override DesignerVerbCollection Verbs => this.m_a;

		public DocumentContainerDesigner()
		{
			this.m_a = new DesignerVerbCollection();
			this.m_a.Add(new DesignerVerb("Add Document", a));
		}

		protected override bool a(Point A_0)
		{
			A_0 = b.PointToClient(A_0);
			LayoutSystemBase layoutSystemAt = b.GetLayoutSystemAt(A_0);
			if (layoutSystemAt is DocumentLayoutSystem)
			{
				DocumentLayoutSystem documentLayoutSystem = (DocumentLayoutSystem)layoutSystemAt;
				if (documentLayoutSystem.g.a.Contains(A_0) || documentLayoutSystem.h.a.Contains(A_0))
				{
					return true;
				}
			}
			return base.GetHitTest(A_0);
		}

		private void a(object A_0, EventArgs A_1)
		{
			IComponentChangeService componentChangeService = (IComponentChangeService)GetService(typeof(IComponentChangeService));
			IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
			ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
			DesignerTransaction designerTransaction = designerHost.CreateTransaction("Add Document");
			ControlLayoutSystem controlLayoutSystem = b.b(b.LayoutSystem);
			if (controlLayoutSystem == null)
			{
				controlLayoutSystem = new DocumentLayoutSystem();
				componentChangeService.OnComponentChanging(b, TypeDescriptor.GetProperties(b)["LayoutSystem"]);
				b.LayoutSystem.LayoutSystems.Add(controlLayoutSystem);
				componentChangeService.OnComponentChanged(b, TypeDescriptor.GetProperties(b)["LayoutSystem"], null, null);
			}
			DockControl dockControl = (DockControl)designerHost.CreateComponent(typeof(DockControl));
			((ComponentDesigner)designerHost.GetDesigner(dockControl)).OnSetComponentDefaults();
			componentChangeService.OnComponentChanging(b, TypeDescriptor.GetProperties(b)["LayoutSystem"]);
			controlLayoutSystem.Controls.Add(dockControl);
			componentChangeService.OnComponentChanged(b, TypeDescriptor.GetProperties(b)["LayoutSystem"], null, null);
			designerTransaction.Commit();
			selectionService.SetSelectedComponents(new object[1] { dockControl });
		}

		public override void a()
		{
			OnSetComponentDefaults();
			a(null, null);
		}

		public override void a(IComponent A_0)
		{
			base.a(A_0);
			b = (DocumentContainer)A_0;
		}
	}
}
