context: #region Header
  //   Vorspire    _,-'/-'/  TeamList.cs
  //   .      __,-; ,'( '/
  //    \.    `-.__`-._`:_,-._       _ , . ``
  //     `:-._,------' ` _,`--` -: `_ , ` ,' :
  //        `---..__,,--'  (C) 2016  ` -'. -'
  //        #  Vita-Nex [http://core.vita-nex.com]  #
  //  {o)xxx|===============-   #   -===============|xxx(o}
  //        #        The MIT License (MIT)          #
  #endregion
  
  #region References
  using System;
  using System.Collections.Generic;
  
  using Server;
  using Server.Gumps;
  using Server.Mobiles;
  
  using VitaNex.SuperGumps;
  using VitaNex.SuperGumps.UI;
  #endregion
  
  namespace VitaNex.Modules.AutoPvP
  {
  	public class PvPTeamListGump : ListGump<PvPTeam>
  	{
  		public PvPTeamListGump(Mobile user, PvPBattle battle, Gump parent = null, bool useConfirm = true)
  			: base(user, parent, emptyText: "There are no battles to display.", title: "PvP Teams")
  		{
  			Battle = battle;
  			UseConfirmDialog = useConfirm;
  
  			ForceRecompile = true;
  		}
  
  		public PvPBattle Battle { get; set; }
  		public bool UseConfirmDialog { get; set; }
  
  		protected override void CompileMenuOptions(MenuGumpOptions list)
  		{
  			list.Clear();
  
  			if (User.AccessLevel >= AutoPvP.Access)
  			{
  				list.AppendEntry(
  					new ListGumpEntry(
  						"Delete All",
  						b =>
  						{
  							if (UseConfirmDialog)
  							{
  								Send(
  									new ConfirmDialogGump(
  										User,
  										this,
  										title: "Delete All Teams?",
  										html:
  											"All teams in the battle will be deleted, erasing all data associated with them.\nThis action can not be reversed.\n\nDo you want to continue?",
  										onAccept: OnConfirmDeleteAllTeams));
  							}
  							else
  							{
  								OnConfirmDeleteAllTeams(b);
  							}
  						},
  						HighlightHue));
  
  				list.AppendEntry(
  					new ListGumpEntry(
  						"New Team",
  						b =>
  							Send(
  								new InputDialogGump(
  									User,
  									this,
  									title: "Team Name",
  									html: "Enter a name for this team.\n255 Chars Max.",
  									input: NameList.RandomName("daemon"),
  									limit: 255,
  									callback: (b1, name) =>
  									{
  										if (String.IsNullOrEmpty(name))
  										{
  											name = NameList.RandomName("daemon");
  										}
  
  										Battle.AddTeam(name, 1, 5, 11 + (List.Count + 1));
  										Refresh(true);
  									})),
  						HighlightHue));
  			}
  
  			var user = User as PlayerMobile;
  
  			if (user != null)
  			{
  				if (Battle.IsParticipant(user))
  				{
  					list.AppendEntry(new ListGumpEntry("Quit & Leave", b => Battle.Eject(User, true)));
  				}
  				else
  				{
  					if (Battle.IsQueued(user))
  					{
  						if (Battle.Queue[user] == Selected)
  						{
  							list.AppendEntry(new ListGumpEntry("Leave Queue", b => Battle.Dequeue(user)));
  						}
  					}
  					else if (!Battle.AutoAssign && Battle.CanQueue(user))
  					{
  						list.AppendEntry(new ListGumpEntry("Join Queue", b => Battle.Enqueue(user)));
  					}
  				}
  			}
  
  			base.CompileMenuOptions(list);
  		}
  
  		protected virtual void OnConfirmDeleteAllTeams(GumpButton button)
  		{
  			foreach (var team in List)
  			{
  				team.Delete();
  			}
  
  			Refresh(true);
  		}
  
  		protected override void CompileList(List<PvPTeam> list)
  		{
  			list.Clear();
  			list.AddRange(Battle.Teams);
  			base.CompileList(list);
  		}
  
  		public override string GetSearchKeyFor(PvPTeam key)
  		{
  			return key != null ? key.Name : base.GetSearchKeyFor(null);
  		}
  
  		protected override void SelectEntry(GumpButton button, PvPTeam entry)
  		{
  			base.SelectEntry(button, entry);
  
  			if (button == null || entry == null || entry.Deleted)
  			{
  				return;
  			}
  
  			var list = new MenuGumpOptions();
  
  			list.AppendEntry(
  				new ListGumpEntry("Overview", b => Send(new PvPTeamOverviewGump(User, entry, Hide(true), UseConfirmDialog))));
  
  			PvPTeam team;
  
  			if (entry.Battle.IsParticipant(User as PlayerMobile, out team))
  			{
  				if (team == entry)
  				{
  					list.AppendEntry(new ListGumpEntry("Quit & Leave", b => entry.Battle.Eject(User as PlayerMobile, true)));
  				}
  			}
  			else if (User is PlayerMobile)
  			{
  				var user = (PlayerMobile)User;
  
  				if (entry.Battle.IsQueued(user))
  				{
  					if (entry.Battle.Queue[user] == entry)
  					{
  						list.AppendEntry(new ListGumpEntry("Leave Queue", b => entry.Battle.Dequeue(user)));
  					}
  				}
  				else if (!entry.Battle.AutoAssign && entry.Battle.CanQueue(user))
  				{
  					list.AppendEntry(new ListGumpEntry("Join Queue", b => entry.Battle.Enqueue(user, entry)));
  				}
  			}
  
  			Send(new MenuGump(User, Refresh(), list, button));
  		}
  
  		protected override void CompileLayout(SuperGumpLayout layout)
  		{
  			base.CompileLayout(layout);
  
  			layout.Add(
  				"button/header/war",
  				() => AddButton(
  					85,
  					15,
  					2026,
  					2025,
  					b =>
  					{
  						var plg = Parent as PvPProfileListGump;
  
  
gt: 						if (plg == null)