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 TeamForm : XtraForm
    {
        MainForm mainForm;
        

        public TeamForm(MainForm _mainForm)
        {
            InitializeComponent();
            mainForm = _mainForm;

            mainForm.DC.LoadTeams();

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

        private void btnAddTeam_Click(object sender, EventArgs e)
        {
            if (txtTeam.Text.Trim() == "")
            {
                MessageBox.Show("팀명을 입력하지 않았습니다..");
                return;
            }
            if (mainForm.DC.Teams.FindAll(x => x.TeamName == txtTeam.Text).Count > 0)
            {
                MessageBox.Show("같은 이름의 팀이 존재합니다.");
                return;
            }

            Team t = new Team();
            t.TeamName = txtTeam.Text;
            t.Players = new List<Tuple<string, string, bool>>();
            mainForm.DC.Teams.Add(t);
            listTeam.Items.Add(txtTeam.Text);

            mainForm.DC.SaveTeams();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            var target = mainForm.DC.Teams.Find(x => x.TeamName == listTeam.SelectedValue.ToString());
            mainForm.DC.Teams.Remove(target);
            listTeam.Items.Remove(listTeam.SelectedItem);

            mainForm.DC.SaveTeams();
        }
    }
}
