using HSUCO_Cargo_Garage_Operation_Program.CustomForm;
using MetroFramework;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace HSUCO_Cargo_Garage_Operation_Program.CustomUserControl
{
    public partial class SettingControl : UserControl
    {

        public SettingControl()
        {
            InitializeComponent();
        }

        public void SettingReset()
        {
            metroTextBox_GarageName.Text = Global.GlobalSettings.GarageName.ToString();
            metroTextBox_CargoLargeMaxCount.Text = Global.GlobalSettings.CargoLargeMaxCount.ToString();
            metroTextBox_CargoOversizedMaxCount.Text = Global.GlobalSettings.CargoOversizedMaxCount.ToString();

            metroTextBox_CargoLargeFee.Text = Global.GlobalSettings.CargoLargeFee.ToString();
            metroTextBox_CargoOversizedFee.Text = Global.GlobalSettings.CargoOversizedFee.ToString();

            metroTextBox_CargoLargeCertificateFee.Text = Global.GlobalSettings.CargoLargeCertificateFee.ToString();
            metroTextBox_CargoOversizedCertificateFee.Text = Global.GlobalSettings.CargoOversizedCertificateFee.ToString();

        }

        private void metroButton_Save_Click(object sender, EventArgs e)
        {
            bool reStart = false;
            int value;
            Settings settings = new Settings();

            settings.GarageName = metroTextBox_GarageName.Text.Trim();
            if (settings.GarageName != Global.GlobalSettings.GarageName)
            {
                reStart = true;
            }
            int.TryParse(metroTextBox_CargoLargeMaxCount.Text, out value);
            settings.CargoLargeMaxCount = value;

            int.TryParse(metroTextBox_CargoOversizedMaxCount.Text, out value);
            settings.CargoOversizedMaxCount = value;

            int.TryParse(metroTextBox_CargoLargeFee.Text, out value);
            settings.CargoLargeFee = value;
            int.TryParse(metroTextBox_CargoOversizedFee.Text, out value);
            settings.CargoOversizedFee = value;
            int.TryParse(metroTextBox_CargoLargeCertificateFee.Text, out value);
            settings.CargoLargeCertificateFee = value;
            int.TryParse(metroTextBox_CargoOversizedCertificateFee.Text, out value);
            settings.CargoOversizedCertificateFee = value;
            Database.SaveSettings(settings);
            
            if (reStart)
            {
                MetroMessageBox.Show(this, "중요 설정이 변경되었습니다. 프로그램을 재시작합니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Restart();
            }
            else
            {
                MetroMessageBox.Show(this, "설정이 완료되었습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            Global.GlobalSettings = settings;

        }

        private void metroButton_init_Click(object sender, EventArgs e)
        {
            SettingReset();
        }

        private void metroButton_Test_Click(object sender, EventArgs e)
        {
            List<ResultSetUserListInformation> test = new List<ResultSetUserListInformation>();
            for (int i = 0; i < 120; i++)
            {
                ResultSetUserListInformation r = new ResultSetUserListInformation();
                r.Area = $"대형-{i}";
                r.ApplicantNo = $"2023-T{i}";
                test.Add(r);
            }
            LotsScreen lotsScreen = new LotsScreen(test);
            lotsScreen.Show();
        }
    }
}
