using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Button = System.Windows.Forms.Button;
using TextBox = System.Windows.Forms.TextBox;

namespace ChamaBasinMiner
{
    public partial class MineralEntry : Form
    {
        int step = 0;
        int MineralCount;
        String MineralSymbol;
        String tempMineralName;
        int tempTonnage;
        List<Minerals> minerals = new List<Minerals>();
        int y = 60;
        public MineralEntry()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //SC1
            makeLabel(10, 20, "How many minerals types do you want to create?");
            txtEntry.Location = new Point(20, 40);
            btnEnterData.Text = "Next";
            btnEnterData.Location = new Point(100, 40);
        }

        //SC2
        private void makeLabel(int x, int y, String str)
        {
            Label b = new Label();
            b.Location = new Point(x, y);
            b.AutoSize = true;
            b.Text = str;
            this.Controls.Add(b);
        }

       
        private void userInputInt(TextBox t)
        {
            int value;
            try   //SC3
            {
                value = int.Parse(t.Text);
                if (value <= 0 || value > 10)  //SC4
                {
                    MessageBox.Show("Your entry needs to be greater than zero and NOT greater than 10. Please enter a new number.", "Error");

                }
                else
                {
                    MineralCount = value;
                    makeLabel(10, 40, "You selected to create " + value + " minerals.");
                    makeLabel(10, 60, "You will now enter in the mineral symbol, its name and how much tonnage has been mined. " + "The market rate for $ per ton will be randomly generated.");
                    makeMineralsProcess("Please enter the three to five alphanumeric mineral symbol");
                }
            }
            catch  //SC3
            {
                MessageBox.Show("You entered an inproper value. Please enter a whole number.", "Error");
                step--;
            }

            
            
        }

          //SC5
        private void Next_Click(object sender, EventArgs e)
        {
            step++;
            if (step == 1)
            {
                userInputInt(txtEntry);
            }
            if(step == 2)
            {
                userInputMineralSymbol();
            }
            if(step == 3)
            {
                userInputTempMineralName();
            }
            if(step == 4)
            {
                userInputTempTonnage();
            }
            if (step == 5)
            {
                Minerals mineral = new Minerals(MineralSymbol, tempMineralName, tempTonnage);
                MineralSymbol = "";
                tempMineralName = "";
                tempTonnage = 0;
                step = 1;
                minerals.Add(mineral);
                MineralCount--;
                if(MineralCount > 0)
                {
                    makeMineralsProcess("Please enter the three to five alphanumeric mineral symbol");
                }
                else
                {
                    for (int q = 0; q < minerals.Count; q++)
                    {
                        y += 25;
                        makeLabel(10, y, minerals[q].toString());
                    }
                }
            }
        }
    
        //STUDENT POINT  //SC6
        private void makeMineralsProcess(String str)
        {
            if(MineralCount > 0)
            {
                y += 20;
                makeLabel(10, y, str);
                y += 20;
                txtEntry.Text = "";
                txtEntry.Location = new Point(20, y); //SC6
                btnEnterData.Location = new Point(100, y); //SC6
            }
            else
            {
                for (int q = 0; q < minerals.Count; q++)
                {
                    minerals[q].toString();
                }
            }
        }
        //STUDENT POINT
        private void userInputMineralSymbol()
        {
            MineralSymbol = txtEntry.Text;  //SC7
            if (MineralSymbol.Length < 3 || MineralSymbol.Length > 5)  //SC7
            {
                MessageBox.Show("That is an improper value. Please Try Again.", "Error");
                step--;
            }
            else
            {
                makeMineralsProcess("Please enter the mineral name.");
            }
        }
        //STUDENT POINT
        private void userInputTempMineralName()
        {
            tempMineralName = txtEntry.Text; //SC8
            if(txtEntry.Text is String)
            {
                makeMineralsProcess("Please enter the total amount of tons that was mined.");
            }
            else
            {
                MessageBox.Show("That is an improper value. Please Try Again.", "Error");
                step--;
            }
        }
        //STUDENT POINT  
        private void userInputTempTonnage()
        {
            String temp = txtEntry.Text;
            try   //SC10
            {
                tempTonnage = int.Parse(temp); //SC9
            }
            catch
            {
                MessageBox.Show("You entered an inproper value. Please enter a whole number.", "Error");
                step--;
            }

        }

        
        private void Enter_KeyDown(object sender, KeyEventArgs e)
        {
            Next_Click(sender, e);//SC11
        }
        
    }
}


