/* Generated by MyraPad at 28/08/2021 19:49:08 */

using System.Threading.Tasks;

namespace Sledgemapper.UI
{
    public partial class PlayerList
    {
        protected readonly CommunicationManager CommunicationManager;

        public PlayerList(CommunicationManager communicationManager)
        {
            BuildUI();
            CommunicationManager = communicationManager;
            BtnInvitePlayer.Click += (s, e) =>
            {
                ShowAddPLayerWindow();
                this.GetContainingWindow().Close();
            };
        }

        public async Task<bool> LoadPlayers()
        {
            var players = await CommunicationManager.GetPlayers(State.Instance.CampaignId);
            if (players is null)
            {
                return false;
            }
            foreach (var player in players)
            {
                var item = new ListItem();
                item.ItemName.Text = player.UserName;
                StackCampaignsList.AddChild(item);
            }

            return true;
        }

        private void ShowAddPLayerWindow()
        {
            new PlayerWindow(CommunicationManager).ShowInModalWindow(Desktop, "Invite player");
        }
    }
}