using Remontor.Connector;
using Remontor.Setting;
using Remontor.Words;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Remontor
{
    internal partial class FlowConteinerSetting : UserControl
    {
        public delegate void DUpdateTree();
        public DUpdateTree UpdateTree;
        public delegate void saveSetting();
        public event saveSetting Save;
        private bool unSave = false;
        public FlowConteinerSetting()
        {
            InitializeComponent();
            Save += settingAppControl1.Save;
            Save += settingSCCMControl1.Save;
            Save += settingWordsControl1.Save;
        }


        public bool HideBar(BarShow barShow)
        {
            if (barShow == BarShow.ShowSetting)
            {
                unSave = false;
                this.Visible = true;
                settingAppControl1.UpdateSetting();
                settingSCCMControl1.UpdateSetting();
                settingWordsControl1.UpdateSetting();
            }
            else
            {
                if (!SConnector.FormMain.ShowOn && !SConnector.FormMain.CloseOn && !unSave && (settingAppControl1.edited() ||
                   settingSCCMControl1.edited() ||
                   settingWordsControl1.edited()))
                {
                    unSave = true;
                    DialogResult result = MessageBox.Show("Изменения не сохраненны. Продолжить?", "Изменения не сохраненны.", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    switch (result)
                    {
                        case DialogResult.Cancel:
                            this.Visible = true;
                            unSave = false;
                            break;
                        case DialogResult.OK:
                            this.Visible = false;
                            unSave = true;
                            break;
                    }

                }
                else if(SConnector.FormMain.ShowOn)
                {
                    this.Visible = true;
                }
                else
                {
                    this.Visible = false;
                }
            }

            return this.Visible;
        }

        private void BtSave_Click(object sender, EventArgs e)
        {
            Save();
            SGlobalSetting.SaveSettig();
            SGlobalSetting.LoadSetting();
            WordsList.MainCategory = SGlobalSetting.LoadWords();
            UpdateTree();
            
        }

        private void BtAbout_Click(object sender, EventArgs e)
        {
            AboutForm aboutForm = new AboutForm();
            aboutForm.Show();   
        }
    }
}
