using System;
using System.IO;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using EasyTabs;

namespace XeroBrowser
{
    public static class Program
    {
        public static AppContainer Container;

        private static TitleBarTabsApplicationContext _applicationContext;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Container = new AppContainer();
            CefSettings settings = new CefSettings();

            if (settings.CefCommandLineArgs.ContainsKey("enable-system-flash"))
                settings.CefCommandLineArgs.Remove("enable-system-flash");
            settings.CefCommandLineArgs.Add("enable-system-flash", "1");
            settings.CefCommandLineArgs.Add("ppapi-flash-path", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pepflashplayer64_32_0_0_465.dll"));
            settings.CefCommandLineArgs.Add("ppapi-flash-version", "32.0.0.465");
            settings.CefCommandLineArgs["plugin-policy"] = "allow";
            settings.UserAgent = "cpprestsdk/2.9.0 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 XeroBrowser/1.0";
            settings.CefCommandLineArgs.Add("enable-media-stream", "1");
            Cef.EnableHighDPISupport();
            settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF";

            Cef.Initialize(settings);

            Container.Tabs.Add(

                new TitleBarTab(Container)
                {
                    Content = new FrmBrowser
                    {
                        Text = @"New Tab"
                    }
                }

            );


            Container.SelectedTabIndex = 0;

            try { 
                _applicationContext = new TitleBarTabsApplicationContext();
                _applicationContext.Start(Container);
                Application.Run(_applicationContext);
            }
            catch (Exception)
            {
                // ignored
            }
        }
    }
}