using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Core.Events;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using OliviaAddInPro.Model;

namespace OliviaAddInPro
{
    internal class Module1 : Module
    {
        private static Module1 _this = null;

        /// <summary>
        /// Retrieve the singleton instance to this module here
        /// </summary>
        public static Module1 Current
        {
            get
            {
                return _this ?? (_this = (Module1)FrameworkApplication.FindModule("OliviaAddInPro_Module"));
            }
        }

        #region Overrides
        /// <summary>
        /// Called by Framework when ArcGIS Pro is closing
        /// </summary>
        /// <returns>False to prevent Pro from closing, otherwise True</returns>
        protected override bool CanUnload()
        {
            //TODO - add your business logic
            //return false to ~cancel~ Application close
            return true;
        }

        protected override bool Initialize() 
        {
            OliviaGlob.Inicia();
            ProjectClosedEvent.Subscribe(OnProjectClosed); 
            return base.Initialize(); 
        }

        private void OnProjectClosed(ProjectEventArgs obj)
        {
            DockPane dockPane = FrameworkApplication.DockPaneManager.Find("OliviaAddInPro_DockpaneLimpieza");
            if (dockPane != null)
            {
                dockPane.IsVisible = false;
            }
            dockPane = FrameworkApplication.DockPaneManager.Find("OliviaAddInPro_DockpaneRecogida");
            if (dockPane != null)
            {
                dockPane.IsVisible = false;
            }
            dockPane = FrameworkApplication.DockPaneManager.Find("OliviaAddInPro_DockpaneConfig");
            if (dockPane != null)
            {
                dockPane.IsVisible = false;
            }
        }

        #endregion Overrides


    }
}
