﻿/*****************************************************************************
*       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;
using System.Windows.Input;
using MapInfo.Types;

namespace MapInfo.MiPro.Samples.LayoutTemplate.Command
{
	/// <summary>
	/// Create a layout using template. Prompts user to select template from 
	/// the directory folder.
	/// </summary>
	/// <seealso cref="System.Windows.Input.ICommand" />
	public class NewLayoutFromTemplateCommand : ICommand
	{
		private readonly IMapInfoPro _application;

		public NewLayoutFromTemplateCommand(IMapInfoPro application)
		{
			if (application == null)
				throw new ArgumentNullException(nameof(application));

			_application = application;
		}

		public bool CanExecute(object parameter)
		{
			return true;
		}

		public event EventHandler CanExecuteChanged;

		protected virtual void OnCanExecuteChanged()
		{
			var handler = CanExecuteChanged;
			handler?.Invoke(this, EventArgs.Empty);
		}

		public void Execute(object parameter)
		{
			var layoutCreator = new LayoutCreator(_application);
			layoutCreator.CreateNewLayoutFromTemplate();
		}
	}
}
