﻿/*****************************************************************************
*       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.Collections.Generic;
using System.Collections.ObjectModel;
using MapInfo.MiPro.Samples.DockingSupport.Models;
using MapInfo.Types;

// ReSharper disable CheckNamespace
namespace MapInfo.MiPro.Samples.DockingSupport.ViewModel
// ReSharper restore CheckNamespace
{
	public sealed class RunningMapBasicApplicationsViewModel : ViewModelMain
	{
		// ReSharper disable once InconsistentNaming
		public ObservableCollection<MapBasicApplication> MBApplications { get; set; }

		public DelegateCommand RefreshCommand { get; set; }

		public RunningMapBasicApplicationsViewModel(IMapInfoPro mapInfoApplication)
			: base(mapInfoApplication)
		{
			UpdatePropertiesWithoutTabbedDocking();

			MBApplications = new ObservableCollection<MapBasicApplication>();
			GetListOfRunningMapBasicApplications(null);
			RefreshCommand = new DelegateCommand(GetListOfRunningMapBasicApplications);
		}

		private void GetListOfRunningMapBasicApplications(object parameter)
		{
			MBApplications.Clear();

			foreach (var mb in MapInfoApplication.MapBasicApplications)
			{
				MBApplications.Add(new MapBasicApplication(mb));
			}
		}

		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", "WindowDetails"));
		}
	}
}