using DevExpress.XtraEditors;
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 lol_coder.Data.DataControl;

namespace lol_coder.Form
{
    public partial class GameForm : XtraForm
    {
        MainForm mainForm;

        public GameForm(MainForm _mainForm)
        {
            InitializeComponent();

            mainForm = _mainForm;

            foreach(Team t in mainForm.DC.Teams)
            {
                listBlue.Items.Add(t.TeamName);
                listRed.Items.Add(t.TeamName);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (listBlue.SelectedItem.ToString().Equals(listRed.SelectedItem.ToString()))
            {
                MessageBox.Show("같은 팀을 선택하였습니다.");
                return;
            }

            //선택한 팀의 맴버를 저장
            string blue = listBlue.SelectedItem.ToString();
            mainForm.DC.LoadPlayer(blue);
            var blueTeam = mainForm.DC.Teams.Find(x => x.TeamName.Equals(blue));

            mainForm.DC.BlueLiner.TeamName = blue;
            mainForm.DC.BlueLiner.Top.Name = blueTeam.Players.Find(x => x.Item2.Equals("탑") && x.Item3.Equals(true)).Item1;
            mainForm.DC.BlueLiner.Jungle.Name = blueTeam.Players.Find(x => x.Item2.Equals("정글") && x.Item3.Equals(true)).Item1;
            mainForm.DC.BlueLiner.Mid.Name = blueTeam.Players.Find(x => x.Item2.Equals("미드") && x.Item3.Equals(true)).Item1;
            mainForm.DC.BlueLiner.ADCarry.Name = blueTeam.Players.Find(x => x.Item2.Equals("원딜") && x.Item3.Equals(true)).Item1;
            mainForm.DC.BlueLiner.Supporter.Name = blueTeam.Players.Find(x => x.Item2.Equals("서폿") && x.Item3.Equals(true)).Item1;


            string red = listRed.SelectedItem.ToString();
            mainForm.DC.LoadPlayer(red);
            var redTeam = mainForm.DC.Teams.Find(x => x.TeamName.Equals(red));

            mainForm.DC.RedLiner.TeamName = red;
            mainForm.DC.RedLiner.Top.Name = redTeam.Players.Find(x => x.Item2.Equals("탑") && x.Item3.Equals(true)).Item1;
            mainForm.DC.RedLiner.Jungle.Name = redTeam.Players.Find(x => x.Item2.Equals("정글") && x.Item3.Equals(true)).Item1;
            mainForm.DC.RedLiner.Mid.Name = redTeam.Players.Find(x => x.Item2.Equals("미드") && x.Item3.Equals(true)).Item1;
            mainForm.DC.RedLiner.ADCarry.Name = redTeam.Players.Find(x => x.Item2.Equals("원딜") && x.Item3.Equals(true)).Item1;
            mainForm.DC.RedLiner.Supporter.Name = redTeam.Players.Find(x => x.Item2.Equals("서폿") && x.Item3.Equals(true)).Item1;

            Close();
        }
    }
}
