/* Generated by MyraPad at 28/08/2021 22:04:11 */
using Myra.Graphics2D.UI;
using Sentry;
using System;

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

        public PlayerWindow(CommunicationManager communicationManager)
		{
            CommunicationManager = communicationManager; 

            BuildUI();
            BtnNewCampaign.Click += OnButtonInvitePlayerClicked;
        }

        private async void OnButtonInvitePlayerClicked(object sender, EventArgs e)
        {
            var localContent = ((TextButton)sender).GetParentContentInWindow<PlayerWindow>();// localWindow.Content as PlayerWindow;
            var isValid = localContent.Content.TxtCampaign.ValidateTextbox();
            if (!isValid)
            {
                return;
            }

            var successful = false;
            try
            {
                await CommunicationManager.Api.InvitePlayer(State.Instance.CampaignName, localContent.Content.TxtCampaign.Text);
            }
            catch (Exception ex)
            {
                SentrySdk.CaptureException(ex);
            }
            this.GetContainingWindow().Close();
        }
    }
}