using System;
using Microsoft.Office.Core;
using OutlookAddin.Ribbon;
using OutlookAddin.Services;

namespace OutlookAddin
{
    public partial class ThisAddIn
    {
        public AddInHost AddInHost { get; private set; } = null!;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {
                AddInHost = new AddInHost(this.Application);
                AddInHost.InitializeSidebar(this.CustomTaskPanes);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(
                    "האתחול של תוסף Marcus-Law נכשל: " + ex.Message,
                    "Marcus-Law OutlookAddin",
                    System.Windows.MessageBoxButton.OK,
                    System.Windows.MessageBoxImage.Error);
            }
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            // Outlook no longer raises Shutdown reliably, but if it does we
            // still want to flush logs and tear down the retry loop.
            try { AddInHost?.Dispose(); } catch { /* ignore */ }
        }

        protected override IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            return new ExplorerRibbon();
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}
