using System;
using System.Drawing;
using System.Windows.Forms;
using NotepadEnhanced.AppState;
using NotepadEnhanced.Localization;
using NotepadEnhanced.Helpers;
using System.Threading;
using System.Globalization;

[assembly: CLSCompliant(true)]
namespace NotepadEnhanced
{
    static class Program
    {
        public static readonly Color SearchDoneColor = Color.FromArgb(255, 192, 192);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] arguments)
        {
            SetCulture();
            // Command line switches will only be expected
            // when the first instance starts, when more app instances
            // pass args into this instance, they will not be processed
            // and we will assume they are filenames
            RecentFileQue.Initialize();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var app = new SingleInstanceBase(arguments);
            app.Run(arguments);
        }

        /// <summary>
        /// Sets the culture for the program, this must be done manuelly because the apps 
        /// non ui culture may need to be set to the users ui culture (needs validation).
        /// Also, display a message to non-english users to better translations
        /// </summary>
        private static void SetCulture()
        {
            if (UserSettings.Instance.FirstBoot)
            {
                UserSettings.Instance.Culture = Thread.CurrentThread.CurrentUICulture.Name;

                if (!UserSettings.Instance.Culture.Equals("en-US", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (Strings.LanguageReport.Length > 0)
                    {
                        MsgBox.Show(Strings.LanguageReport, MessageBoxIcon.Asterisk);
                    }
                }
            }

            string cultureNotation = UserSettings.Instance.Culture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(cultureNotation);
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(cultureNotation);
        }
    }
}