/*****************************************************************************
*       Copyright 1985, 2020 Precisely.
*       All rights reserved.
*
*       This document contains unpublished, confidential, and proprietary
*       information of Precisely. No disclosure or use of any portion of
*       the contents of this document may be made without the express 
*       written consent of Precisely.
*****************************************************************************/

using System.AddIn.Pipeline;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Data;
using MapInfo.MiPro.Samples.DockingSupport.Models;
using MapInfo.MiPro.Samples.DockingSupport.View;
using MapInfo.Types;

// ReSharper disable CheckNamespace
namespace MapInfo.MiPro.Samples.DockingSupport.ViewModel
// ReSharper restore CheckNamespace
{
	public sealed class MapInfoWindowDetailsViewModel : ViewModelMain
	{
		public MyObservableCollection<DockingManagerProperty> DockingProperties { get; set; }

		public MapInfoWindowDetailsViewModel(IMapInfoPro mapinfoApplication) : base (mapinfoApplication)
		{
			UpdatePropertiesWithoutTabbedDocking();

			DockingProperties = new MyObservableCollection<DockingManagerProperty>
			{
				new DockingManagerProperty
				{
					PropertyName = "CanAutoHide",
					PropertyDescription = "Specifies whether the child element can be hidden automatically or not.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "CanDock",
					PropertyDescription = "Specifies whether the child element can be docked or not.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "CanClose",
					PropertyDescription = "Specifies whether the child element can be closed or not.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "CanDrag",
					PropertyDescription = "Specifies whether the child can be dragged from Dock to Float state.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "CanFloat",
					PropertyDescription = "Specifies whether the child element is Floatable or not.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "DesiredHeightInDockedMode",
					PropertyDescription = "Specifies the Desired Height of the child element in Docked State.",
					PropertyType = typeof(double),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "DesiredWidthInDockedMode",
					PropertyDescription = "Specifies the Desired Width of the child element in Docked State.",
					PropertyType = typeof(double),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "DockAbility",
					PropertyDescription = "Specifies the dockability of the child element.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"All",
						"Bottom",
						"Horizontal",
						"Left",
						"None",
						"Right",
						"Tabbed",
						"Top",
						"Vertical"
					},
					IsEditableProperty = true
				},
				
				new DockingManagerProperty
				{
					PropertyName = "DesiredWidthInDockedMode",
					PropertyDescription = "Specifies the Desired Width of the child element in Docked State.",
					PropertyType = typeof(double),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "FloatWindowHeight",
					PropertyDescription = "Specifies the height of the Float Window of a child element.",
					PropertyType = typeof(double),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "FloatWindowWidth",
					PropertyDescription = "Specifies the width of the Float Window of a child element.",
					PropertyType = typeof(double),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "Header",
					PropertyDescription = "Specifies the Header for the Children of DockingManager.",
					PropertyType = typeof(object),
					PropertyValues = new List<string>
					{
						"0.0"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "Icon",
					PropertyDescription = "Specifies the icon for Document Child in MDI mode.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Some Icon Path"
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "IsContextMenuButtonVisible",
					PropertyDescription = "Specifies the visibility of the Contextmenu button for the individual children of Docking Manager.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "IsContextMenuVisible",
					PropertyDescription = "Specifies the visibility of the Contextmenu button for the individual children of Docking Manager.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "NoHeader",
					PropertyDescription = "Specifies whether to display the headers of Docked children or not.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "SideInDockedMode",
					PropertyDescription = "Specifies the DockSide while the child is in Docked State with respect to the parent.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Top",
						"Left",
						"Right",
						"Bottom",
						"Tabbed"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "SideInFloatMode",
					PropertyDescription = "Specifies the DockSide while the child is in Float State with respect to the parent.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Top",
						"Left",
						"Right",
						"Bottom",
						"Tabbed"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "TargetNameInDockedMode",
					PropertyDescription = "Specifies the target of the child element (which needs to be docked), in the Dock State of the child.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Name of any open window which can be docked."
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "TargetNameInFloatMode",
					PropertyDescription = "Specifies the target of the child that needs to be docked in the Float state of the child.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Name of any open window which can be floated."
					},
					IsEditableProperty = false
				},

				new DockingManagerProperty
				{
					PropertyName = "SizetoContentInFloat",
					PropertyDescription = "Specifies whether the Float Window needs to be sized to its child content.",
					PropertyType = typeof(bool),
					PropertyValues = new List<string>
					{
						"true",
						"false"
					},
					IsEditableProperty = true
				},

				new DockingManagerProperty
				{
					PropertyName = "State",
					PropertyDescription = "Specifies the state of children of the Docking Manager.",
					PropertyType = typeof(string),
					PropertyValues = new List<string>
					{
						"Dock",
						"Float",
						"Document",
						"AutoHidden",
						"Hidden"
					},
					IsEditableProperty = true
				}
			};

			DockingProperties.ChildElementPropertyChanged += DockingManagerPropertyChanged;
		}

		private void DockingManagerPropertyChanged(MyObservableCollection<DockingManagerProperty>.ChildElementPropertyChangedEventArgs e)
		{
			var prop = e.ChildElement as DockingManagerProperty;

			if (prop != null)
			{
				MapInfoApplication.DockingManager.SetDockingManagerProperty(SelectedMapInfoWindow.Window, prop.PropertyName, prop.SelectedPropertyValue);
				DockingProperties.ChildElementPropertyChanged -= DockingManagerPropertyChanged;
				prop.PropertyName = prop.PropertyName;
				DockingProperties.ChildElementPropertyChanged += DockingManagerPropertyChanged;
			}
			
		}

		public override void UpdatePropertiesForTabbedDocking()
		{
			if (Properties == null)
			{
				Properties = new List<KeyValuePair<string, string>>();
			}
			else
			{
				Properties.Clear();
			}
			
			Properties.Add(new KeyValuePair<string, string>("State", "Dock"));
			Properties.Add(new KeyValuePair<string, string>("CanFloat", "True"));
			Properties.Add(new KeyValuePair<string, string>("DesiredWidthInDockedMode", "400"));
			Properties.Add(new KeyValuePair<string, string>("SideInDockedMode", "Tabbed"));
			Properties.Add(new KeyValuePair<string, string>("TargetNameInDockedMode", "MBApplications"));
		}
	}
}