using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HaloMap;

namespace Mutation
{
    public enum ProjectType
    {
        New,
        Decompile,
        None
    }

    public partial class NewProjectDialog : Form
    {
        ProjectType type = ProjectType.New;

        public NewProjectDialog(ProjectType type)
        {
            InitializeComponent();
            this.type = type;
        }

        private void NewProjectDialog_Load(object sender, EventArgs e)
        {
            if (type == ProjectType.Decompile)
                radioGroup1.SelectedIndex = 3;
            else
                radioGroup1.SelectedIndex = 2;
        }

        private void wizardControl1_NextClick(object sender, DevExpress.XtraWizard.WizardCommandButtonClickEventArgs e)
        {
            if (wizardControl1.SelectedPageIndex == 1 && radioGroup1.SelectedIndex == 3)
            {
                //Decompile
                type = ProjectType.Decompile;
               
                // Add some Controls
                wizardPage1.Text = "Decompile";
                wizardPage1.Controls.Clear();
                wizardPage1.Controls.Add(new Decompile());
            }
            else if (wizardControl1.SelectedPageIndex == 1 && radioGroup1.SelectedIndex != 3)
            {
                //New Project
                type = ProjectType.New;
            }
        }

        private void wizardControl1_FinishClick(object sender, CancelEventArgs e)
        {
            if (type == ProjectType.Decompile)
            {
                //Open the Map and Read it
                Map map = new Map(((Decompile)wizardPage1.Controls[0]).txtMap.Text);
                map.Read(null);
                Global.Globals.RecentProj = ((Decompile)wizardPage1.Controls[0]).txtProjectDirectory.Text + "\\" + map.Header.MapName.TrimEnd('\0') + ".h2project";

                //Progress
                this.Hide();
                Updater updater = new Updater(map, ((Decompile)wizardPage1.Controls[0]).txtProjectDirectory.Text);
                updater.ShowInTaskbar = false;
                updater.ShowDialog();
                this.Close();
            }
            else if (type == ProjectType.New)
            {

            }
        }

        private void wizardControl1_CancelClick(object sender, CancelEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to cancel? Your project will not be saved.", "New Project Dialog", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.Close();
            }
        }
    }
}
