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 CarManagerV3.Manager;

namespace CarManagerV3.Forms
{
    public partial class UpdatePromptForm : Form
    {
        public UpdatePromptForm(string currentVersion, string latestVersion)
        {
            InitializeComponent();
            lblInstalledVersion.Text = lblInstalledVersion.Text.Replace("?.?.?", currentVersion);
            lblLatestVersion.Text = lblLatestVersion.Text.Replace("?.?.?", latestVersion);
            if (Updater.IsLatestVersionPrerelease())
            {
                lblLatestVersion.Text += " (Pre-release)";
            }

        }

        private void btnDismissUpdate_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnInstallUpdate_Click(object sender, EventArgs e)
        {
            PleaseWait loadForm = new PleaseWait("Downloading the newest version...");
            try
            {
                this.Enabled = false;
                loadForm.Show();
                Application.DoEvents();
                //return;
                Updater.DownloadNewestInstaller();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred while trying to download the update: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Enabled = true;
            loadForm.Close();
            this.Close();

        }

        private void btnReadChangelog_Click(object sender, EventArgs e)
        {
            Updater.OpenReleasePage();
        }
    }
}
