using Cute;
using UnityEngine;
using Wizard;

internal class ColosseumCardPanel : MyPageCardPanel
{
	private const string DEFAULT_GRAND_PRIX_ID = "0";

	[SerializeField]
	private GameObject _infoRoot;

	[SerializeField]
	private UILabel _infoTitleLabel;

	[SerializeField]
	private UILabel _infoNextRoundLabel;

	[SerializeField]
	private UILabel _infoTimeLabel;

	[SerializeField]
	private UILabel _nameLabel;

	[SerializeField]
	private GameObject _freeEntryIcon;

	[SerializeField]
	private UISprite _panelLineSprite;

	private const int SECONDS_PER_MINUTE = 60;

	private const float SECONDS_TASK_END_NEXT_INTERVAL = 0.5f;

	private float _updateTimer;

	private bool _isFreeEntryIconDisplayPermission;

	public GameObject MyPageFreeEntryIcon { private get; set; }

	public override void CheckMaintenanceType()
	{
		base.CheckMaintenanceType();
		if (Data.MaintenanceCodeList.Contains(maintenanceType))
		{
			_infoRoot.SetActive(value: false);
		}
		else
		{
			_infoRoot.SetActive(value: true);
		}
	}

	public void SetIconDisplayPermission(bool isPermission)
	{
		_isFreeEntryIconDisplayPermission = isPermission;
		NowUpdate();
	}

	public override string GetResourcePath(bool isfetch)
	{
		if (Data.ArenaData.ColosseumData.ColorCodeId == "0")
		{
			return base.GetResourcePath(isfetch);
		}
		return Toolbox.ResourcesManager.GetAssetTypePath("menu_arena_colosseum_gp_" + Data.ArenaData.ColosseumData.ColorCodeId, ResourcesManager.AssetLoadPathType.CardMenu, isfetch);
	}

	public void NowUpdate()
	{
		_updateTimer = 0f;
	}

	private void OnEnable()
	{
		NowUpdate();
	}

	private void OnApplicationPause(bool pause)
	{
		if (!pause)
		{
			NowUpdate();
		}
	}

	private void Update()
	{
		ArenaColosseum colosseumData = Data.ArenaData.ColosseumData;
		if (colosseumData.IsColosseumPeriod)
		{
			_updateTimer -= Time.deltaTime;
			if (_updateTimer < 0f)
			{
				SystemText systemText = Data.SystemText;
				double num = colosseumData.RemainingServerUnixTime + (double)Time.realtimeSinceStartup - (double)colosseumData.RemainingSinceTime;
				_updateTimer = (float)(60.0 - num % 60.0);
				_nameLabel.text = colosseumData.Name;
				string id;
				string id2;
				string id3;
				if (colosseumData.IsRoundPeriod)
				{
					id = "Colosseum_0044";
					id2 = "Colosseum_0057";
					id3 = "Colosseum_0058";
				}
				else
				{
					id = "Colosseum_0059";
					id2 = "Colosseum_0060";
					id3 = "Colosseum_0061";
				}
				string text;
				if (num > colosseumData.RemainingUnixTime)
				{
					text = systemText.Get(id3, "0");
					if (colosseumData.StageNo != ArenaColosseum.eStageNo.FinalStage || (!colosseumData.IsRoundPeriod && colosseumData.IsColosseumPeriod))
					{
						ColosseumEntryInfoTask task = new ColosseumEntryInfoTask();
						UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, ColosseumEntryInfoTaskSuccess));
					}
				}
				else
				{
					double num2 = colosseumData.RemainingUnixTime - num;
					text = ((num2 < 3600.0) ? systemText.Get(id3, ((int)(num2 / 60.0) + 1).ToString()) : ((!(num2 < 86400.0)) ? systemText.Get(id, ((int)(num2 / 86400.0)).ToString()) : systemText.Get(id2, ((int)(num2 / 3600.0)).ToString())));
				}
				if (colosseumData.IsRoundPeriod)
				{
					string text2 = ((colosseumData.StageNo != ArenaColosseum.eStageNo.FinalStage) ? systemText.Get("Colosseum_0062", systemText.Get("Colosseum_0007", ((int)colosseumData.StageNo).ToString())) : systemText.Get("Colosseum_0062", systemText.Get("Colosseum_0008")));
					_infoTitleLabel.text = text2;
					_infoNextRoundLabel.text = systemText.Get("Colosseum_0043");
					_infoTimeLabel.text = text;
					if (_isFreeEntryIconDisplayPermission)
					{
						_freeEntryIcon.SetActive(colosseumData.IsFreeEntry);
					}
					else
					{
						_freeEntryIcon.SetActive(value: false);
					}
					UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
					MyPageFreeEntryIcon.SetActive(colosseumData.IsFreeEntry);
				}
				else
				{
					string text3 = ((colosseumData.StageNo != ArenaColosseum.eStageNo.Stage1) ? systemText.Get("Colosseum_0045") : systemText.Get("Colosseum_0041"));
					string text4 = ((colosseumData.StageNo != ArenaColosseum.eStageNo.FinalStage) ? systemText.Get("Colosseum_0042", systemText.Get("Colosseum_0007", ((int)colosseumData.StageNo).ToString())) : systemText.Get("Colosseum_0042", systemText.Get("Colosseum_0008")));
					_infoTitleLabel.text = text3;
					_infoNextRoundLabel.text = text4;
					_infoTimeLabel.text = text;
					_freeEntryIcon.SetActive(value: false);
					UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
					MyPageFreeEntryIcon.SetActive(value: false);
				}
			}
		}
		SetUILabelParam();
	}

	private void ColosseumEntryInfoTaskSuccess(NetworkTask.ResultCode inResult)
	{
		_updateTimer = 0.5f;
	}

	private void SetUILabelParam()
	{
		string colorCodeId = Data.ArenaData.ColosseumData.ColorCodeId;
		if (colorCodeId == "0")
		{
			_panelLineSprite.color = ColorCode.Get(eColorCodeId.CARD_PANEL_GP_LINE_SPRITE_COLOR);
			base.TitleLabel.applyGradient = true;
			base.TitleLabel.gradientTop = ColorCode.Get(eColorCodeId.CARD_PANEL_GP_TITLE_GRAD_TOP);
			base.TitleLabel.gradientBottom = ColorCode.Get(eColorCodeId.CARD_PANEL_GP_TITLE_GRAD_BOTTOM);
			base.TitleLabel.effectStyle = UILabel.Effect.Outline8;
			base.TitleLabel.effectColor = ColorCode.Get(eColorCodeId.CARD_PANEL_GP_TITLE_OUTLINE);
			_infoTitleLabel.effectStyle = UILabel.Effect.None;
		}
		else
		{
			_panelLineSprite.color = ColorCode.GetWithString("GP" + colorCodeId + "_CARD_PANEL_LINE_SPRITE_COLOR");
			base.TitleLabel.gradientTop = ColorCode.GetWithString("GP" + colorCodeId + "_CARD_PANEL_TITLE_GRAD_TOP");
			base.TitleLabel.gradientBottom = ColorCode.GetWithString("GP" + colorCodeId + "_CARD_PANEL_TITLE_GRAD_BOTTOM");
			base.TitleLabel.effectStyle = UILabel.Effect.Outline8;
			base.TitleLabel.effectColor = ColorCode.GetWithString("GP" + colorCodeId + "_CARD_PANEL_TITLE_OUTLINE");
			_infoTitleLabel.effectStyle = UILabel.Effect.Outline8;
			_infoTitleLabel.effectColor = ColorCode.GetWithString("GP" + colorCodeId + "_CARD_PANEL_ROUND_INFO_OUTLINE");
		}
	}
}
