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

namespace Administration
{
    public partial class FindPlayerControl : UserControl
    {
        private List<SimplePlayer> playersList;

        public FindPlayerControl()
        {
            InitializeComponent();     
        }

        private void playersListTable_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.RowIndex < playersListTable.RowCount)
            {
                SimplePlayer playerRow = (SimplePlayer)playersListTable.Rows[e.RowIndex].DataBoundItem;

                if (playerRow != null)
                {
                    PlayerInformationRequest request = new PlayerInformationRequest { player_id = playerRow.ID };
                    ClientCommunicator.Instance.SendMessage(request);
                }
            }
        }

        private void findPlayerButton_Click(object sender, EventArgs e)
        {
            PlayersRequest request = new PlayersRequest { player_login_filter = playerNameBox.Text };
            ClientCommunicator.Instance.SendMessage(request);
        }

        public void SetupFromPlayersList(PlayerInformation[] playerInformations)
        {
            this.playersList = new List<SimplePlayer>();

            foreach (PlayerInformation playerInformation in playerInformations) {
                this.playersList.Add(new SimplePlayer(playerInformation.player_id, playerInformation.player_login, playerInformation.player_name));
            }

            playersListTable.DataSource = playersList;
        }
    }
}
