using System.Collections.Generic;
using UnityEngine;
using Wizard;
using Wizard.ErrorDialog;

public class ColosseumDetail : MonoBehaviour
{
	private enum eTitleLabel
	{
		StageName,
		TimeStart,
		TimeEnd,
		Max
	}

	private enum eGroupLabel
	{
		Group,
		BattleNum,
		BreakThrough,
		Retry
	}

	[SerializeField]
	private UILabel _formatLabel;

	[SerializeField]
	private UILabel _timeLabel;

	[SerializeField]
	private UILabel _ownStatusLabel;

	[SerializeField]
	private UILabel[] _round1TitleLabels;

	[SerializeField]
	private UILabel[] _round2TitleLabels;

	[SerializeField]
	private UILabel[] _round3TitleLabels;

	[SerializeField]
	private UILabel[] _round1GroupLabels;

	[SerializeField]
	private UILabel[] _round2GroupALabels;

	[SerializeField]
	private UILabel[] _round2GroupBLabels;

	[SerializeField]
	private UILabel[] _round3GroupALabels;

	[SerializeField]
	private UILabel[] _round3GroupBLabels;

	public void Init(DialogBase inDialog)
	{
		SystemText systemText = Wizard.Data.SystemText;
		ArenaColosseum colosseumData = Wizard.Data.ArenaData.ColosseumData;
		inDialog.SetSize(DialogBase.Size.M);
		inDialog.SetTitleLabel(systemText.Get("Common_0022"));
		inDialog.SetButtonLayout(DialogBase.ButtonLayout.GrayBtn_GrayBtn);
		inDialog.SetButtonText(systemText.Get("Colosseum_0023"), systemText.Get("Colosseum_0025"));
		inDialog.onPushButton1 = delegate
		{
			if (!string.IsNullOrEmpty(Wizard.Data.ArenaData.ColosseumData.AnnounceNo))
			{
				UIManager.GetInstance().WebViewHelper.OpenAnnounceWebView(Wizard.Data.ArenaData.ColosseumData.AnnounceNo);
			}
			else
			{
				Dialog.Create(4416);
			}
		};
		inDialog.onPushButton2 = delegate
		{
			if (Wizard.Data.ArenaData.ColosseumData.Rule == ArenaColosseum.eRule.Avatar)
			{
				UIManager.GetInstance().StartFirstTips(FirstTips.TipsType.HeroesGrandPrix);
			}
			else if (Wizard.Data.ArenaData.ColosseumData.Rule == ArenaColosseum.eRule.WindFall)
			{
				UIManager.GetInstance().StartFirstTips(FirstTips.TipsType.ColosseumWindFall);
			}
			else if (Wizard.Data.ArenaData.ColosseumData.Rule == ArenaColosseum.eRule.TwoPickChaos)
			{
				UIManager.GetInstance().StartFirstTips(FirstTips.TipsType.Colosseum2PickChaos, null, 0, Wizard.Data.ArenaData.ColosseumData.ChaoseTipsId);
			}
			else
			{
				UIManager.GetInstance().CheckFirstTips(FirstTips.TipsType.ColosseumInfo);
			}
		};
		inDialog.isNotCloseWindowButton1 = true;
		inDialog.isNotCloseWindowButton2 = true;
		string text = colosseumData.Rule switch
		{
			ArenaColosseum.eRule.TwoPick => (colosseumData.IsNormalTwoPick ? systemText.Get("Arena_0002") : systemText.Get("Colosseum_0105")) + " " + systemText.Get("Colosseum_0093"), 
			ArenaColosseum.eRule.TwoPickChaos => systemText.Get("Chaos_FormatName"), 
			ArenaColosseum.eRule.HOF => systemText.Get("Colosseum_0108"), 
			ArenaColosseum.eRule.WindFall => systemText.Get("Colosseum_0115"), 
			ArenaColosseum.eRule.Crossover => systemText.Get("Common_0166"), 
			ArenaColosseum.eRule.MyRotation => systemText.Get("Common_0178"), 
			ArenaColosseum.eRule.Avatar => systemText.Get("HeroesBattle_0001"), 
			_ => ((colosseumData.DeckFormat == Format.Rotation) ? systemText.Get("Common_0154") : systemText.Get("Common_0155")) + systemText.Get("Colosseum_0093"), 
		};
		_formatLabel.text = systemText.Get("Colosseum_0054", text);
		_timeLabel.text = systemText.Get("Colosseum_0084", colosseumData.ColosseumTimeText);
		OwnStatusLabelUpdate();
		List<UILabel[]> list = new List<UILabel[]>();
		list.Add(_round1TitleLabels);
		list.Add(_round2TitleLabels);
		list.Add(_round3TitleLabels);
		for (int num = 1; num < 4; num++)
		{
			UILabel[] array = list[num - 1];
			ArenaColosseum.eRound eRound = (ArenaColosseum.eStageNo)num switch
			{
				ArenaColosseum.eStageNo.Stage1 => ArenaColosseum.eRound.Round1, 
				ArenaColosseum.eStageNo.Stage2 => ArenaColosseum.eRound.Round2A, 
				_ => ArenaColosseum.eRound.FinalA, 
			};
			UILabel uILabel = array[0];
			if (num == 3)
			{
				uILabel.text = systemText.Get("Colosseum_0008");
			}
			else
			{
				uILabel.text = systemText.Get("Colosseum_0007", num.ToString());
			}
			UILabel uILabel2 = array[1];
			uILabel2.text = colosseumData.DetailData[(int)(eRound - 1)].RoundTimeStartText;
			UILabel uILabel3 = array[2];
			uILabel3.text = colosseumData.DetailData[(int)(eRound - 1)].RoundTimeEndText;
			if (num == (int)colosseumData.FocusStageNo)
			{
				uILabel.text = AddColorCode(uILabel.text);
				uILabel2.text = AddColorCode(uILabel2.text);
				uILabel3.text = AddColorCode(uILabel3.text);
			}
		}
		List<UILabel[]> list2 = new List<UILabel[]>();
		list2.Add(_round1GroupLabels);
		list2.Add(_round2GroupBLabels);
		list2.Add(_round2GroupALabels);
		list2.Add(_round3GroupBLabels);
		list2.Add(_round3GroupALabels);
		for (int num2 = 1; num2 < 6; num2++)
		{
			UILabel[] array = list2[num2 - 1];
			array[0].text = colosseumData.DetailData[num2 - 1].GroupName;
			array[1].text = systemText.Get("Colosseum_0075", colosseumData.DetailData[num2 - 1].MaxBattleNum.ToString());
			if (num2 >= 4)
			{
				array[3].text = systemText.Get("Colosseum_0088", colosseumData.DetailData[num2 - 1].MaxEntryNum.ToString());
			}
			else
			{
				array[3].text = systemText.Get("Colosseum_0078", colosseumData.DetailData[num2 - 1].MaxEntryNum.ToString());
			}
			UILabel uILabel4 = array[2];
			if (num2 == 1)
			{
				string text2 = systemText.Get("Colosseum_0076", colosseumData.DetailData[num2 - 1].BreakThroughNum.ToString(), systemText.Get("Colosseum_0020"));
				string text3 = systemText.Get("Colosseum_0080", (colosseumData.DetailData[num2 - 1].BreakThroughNum - 1).ToString(), systemText.Get("Colosseum_0021"));
				uILabel4.text = text2 + "\n" + text3;
			}
			else if (num2 >= 4)
			{
				uILabel4.text = systemText.Get("Colosseum_0104", colosseumData.FinalRoundEliminateCount.ToString());
			}
			else
			{
				switch (num2)
				{
				case 3:
				{
					string text4 = systemText.Get("Colosseum_0076_Group", colosseumData.DetailData[num2 - 1].BreakThroughNum.ToString(), systemText.Get("Colosseum_0020"));
					string text5 = systemText.Get("Colosseum_0076_Group", colosseumData.DetailData[1].BreakThroughNum.ToString(), systemText.Get("Colosseum_0021"));
					uILabel4.text = text4 + "\n" + text5;
					break;
				}
				case 2:
					uILabel4.text = systemText.Get("Colosseum_0076_Group", colosseumData.DetailData[num2 - 1].BreakThroughNum.ToString(), systemText.Get("Colosseum_0021"));
					break;
				}
			}
			if (colosseumData.GetStageNoFromRoundId((ArenaColosseum.eRound)num2) == colosseumData.FocusStageNo)
			{
				for (int num3 = 0; num3 < array.Length; num3++)
				{
					array[num3].text = AddColorCode(array[num3].text);
				}
			}
		}
	}

	private void OwnStatusLabelUpdate()
	{
		SystemText systemText = Wizard.Data.SystemText;
		ArenaColosseum colosseumData = Wizard.Data.ArenaData.ColosseumData;
		_ownStatusLabel.text = string.Empty;
		if (colosseumData.IsClear)
		{
			_ownStatusLabel.text = systemText.Get("Colosseum_0038", colosseumData.Name);
		}
		else if (colosseumData.IsFinalRound())
		{
			_ownStatusLabel.text = string.Empty;
		}
		else if (!colosseumData.IsRoundPeriod && colosseumData.StageNo == ArenaColosseum.eStageNo.Stage1)
		{
			_ownStatusLabel.text = string.Empty;
		}
		else if (!colosseumData.IsRoundPeriod)
		{
			if (colosseumData.StageNo == ArenaColosseum.eStageNo.Stage2)
			{
				if (colosseumData.NextRound == ArenaColosseum.eRound.Round2A || colosseumData.NextRound == ArenaColosseum.eRound.Round2B)
				{
					_ownStatusLabel.text = systemText.Get("Colosseum_0048", colosseumData.GetGroupText(colosseumData.NextRound));
				}
			}
			else if (colosseumData.StageNo == ArenaColosseum.eStageNo.FinalStage)
			{
				if (colosseumData.NextRound == ArenaColosseum.eRound.Undecided || colosseumData.NextRound == ArenaColosseum.eRound.Lose)
				{
					_ownStatusLabel.text = systemText.Get("Colosseum_0052");
				}
				else if (colosseumData.NextRound == ArenaColosseum.eRound.FinalA || colosseumData.NextRound == ArenaColosseum.eRound.FinalB)
				{
					_ownStatusLabel.text = systemText.Get("Colosseum_0037_Group", colosseumData.GetGroupText(colosseumData.NextRound));
				}
			}
		}
		else if (colosseumData.Round == ArenaColosseum.eRound.Round1)
		{
			if (colosseumData.NextRound == ArenaColosseum.eRound.Round2A || colosseumData.NextRound == ArenaColosseum.eRound.Round2B)
			{
				_ownStatusLabel.text = systemText.Get("Colosseum_0048", colosseumData.GetGroupText(colosseumData.NextRound));
			}
		}
		else if ((colosseumData.Round == ArenaColosseum.eRound.Round2A || colosseumData.Round == ArenaColosseum.eRound.Round2B) && colosseumData.NextRound != ArenaColosseum.eRound.Lose)
		{
			if (colosseumData.NextRound == ArenaColosseum.eRound.Undecided)
			{
				_ownStatusLabel.text = systemText.Get("Colosseum_0052");
			}
			else if (colosseumData.NextRound == ArenaColosseum.eRound.FinalA || colosseumData.NextRound == ArenaColosseum.eRound.FinalB)
			{
				_ownStatusLabel.text = systemText.Get("Colosseum_0037_Group", colosseumData.GetGroupText(colosseumData.NextRound));
			}
		}
		else
		{
			_ownStatusLabel.text = string.Empty;
		}
		if (_ownStatusLabel.text != string.Empty)
		{
			_ownStatusLabel.text = AddColorCode(_ownStatusLabel.text);
		}
	}

	private string AddColorCode(string inOriginalText)
	{
		return "[fcd24a]" + inOriginalText + "[-]";
	}
}
