using DevExpress.XtraEditors;
using lol_coder.Forms.Frame;
using LolDataRequestLib;
using Moda.KString;
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 LolDataRequestLib.DataManager;

namespace lol_coder.Forms
{
    public partial class ChampSearchForm : XtraForm
    {
        BanPickFrame banPickFrame;

        public ChampSearchForm(BanPickFrame _banPickFrame, string selectedChampName)
        {
            InitializeComponent();
            banPickFrame = _banPickFrame;

            textEdit1.Text = selectedChampName;
            textEdit1_EditValueChanged(null, null);
        }

        private void textEdit1_EditValueChanged(object sender, EventArgs e)
        {
            string s = textEdit1.Text;

            imageListBoxControl1.Items.Clear();

            imageListBoxControl1.Items.Add("초기화");
            imageListBoxControl1.Items.Add("없음선택");

            foreach (var v in DataManager.getInstance().mChampionTable)
            {
                if (v.Value.champNameKOR.KContains(s))
                {
                    imageListBoxControl1.Items.Add(v.Value.champNameKOR);
                }
                else if (v.Value.champNameENG.ToLower().Contains(s.ToLower()))
                {
                    imageListBoxControl1.Items.Add(v.Value.champNameKOR);
                }
                    
            }
            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (imageListBoxControl1.SelectedIndex > -1)
            {
                string selected = imageListBoxControl1.SelectedItem.ToString();

                if (selected.Equals("초기화"))
                {
                    ChampionInfoVO v = new ChampionInfoVO();
                    v.champNameKOR = "초기화";
                    v.champNameENG = "";
                    banPickFrame.selectedChamp = v;
                }
                else if (selected.Equals("없음선택"))
                {
                    ChampionInfoVO v = new ChampionInfoVO();
                    v.champNameKOR = "없음선택";
                    v.champNameENG = " ";
                    banPickFrame.selectedChamp = v;
                }
                else
                {
                    foreach (var v in DataManager.getInstance().mChampionTable)
                    {
                        if (v.Value.champNameKOR.Equals(selected)) banPickFrame.selectedChamp = v.Value;
                    }
                }

                this.Close();
            }
            else
            {
                MessageBox.Show("선택된 케릭터가 없습니다..");
            }
        }
    }
}
