using UnityEngine;
using Wizard.ErrorDialog;
using Wizard.Scripts.Network.Data.TaskData.Arena;

namespace Wizard;

public class CompetitionDetail : MonoBehaviour
{
	[SerializeField]
	private GameObject _prefabRewardDialog;

	[SerializeField]
	private CardDetailUI _cardDetailDialog;

	[SerializeField]
	private GameObject _rewardRoot;

	[SerializeField]
	private UILabel _formatLabel;

	[SerializeField]
	private UILabel _entryPeriodTimeLabel;

	[SerializeField]
	private UILabel _openPeriodTimeLabel;

	[SerializeField]
	private UILabel _maxNumLabel;

	[SerializeField]
	private UILabel _conditionLable;

	[SerializeField]
	private UILabel _entryNum;

	[SerializeField]
	private UILabel _tryNum;

	private const int COMPETITION_ANNOUNCE_ID_NOT_SET_ERROR_CODE = 5516;

	public void Init(DialogBase inDialog, ArenaCompetition data, bool isEntry)
	{
		SystemText systemText = Data.SystemText;
		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"));
		string text = "";
		text = data.DeckFormat switch
		{
			Format.TwoPick => systemText.Get("Arena_0002"), 
			Format.Rotation => systemText.Get("Common_0154"), 
			_ => systemText.Get("Common_0155"), 
		};
		_formatLabel.text = systemText.Get("Colosseum_0054", text) + systemText.Get("Colosseum_0093");
		_openPeriodTimeLabel.text = systemText.Get("Competition_0029") + " : " + data.NowRoundTimeText;
		_entryPeriodTimeLabel.text = systemText.Get("Competition_0028") + " : " + data.EntryTimeText;
		_maxNumLabel.text = systemText.Get("Competition_0023", data.MaxBattleCount.ToString());
		_conditionLable.text = systemText.Get("Colosseum_0104", data.MaxLoseCount.ToString());
		_entryNum.text = systemText.Get("Colosseum_0088", data.MaxEntryCount.ToString());
		_tryNum.text = systemText.Get("Competition_0042", data.MaxChallengeCount.ToString());
		inDialog.onPushButton1 = delegate
		{
			if (!string.IsNullOrEmpty(data.AnnounceId))
			{
				UIManager.GetInstance().WebViewHelper.OpenAnnounceWebView(data.AnnounceId);
			}
			else
			{
				Wizard.ErrorDialog.Dialog.Create(5516);
			}
		};
		inDialog.onPushButton2 = delegate
		{
			UIManager.GetInstance().StartFirstTips(CompetitionUtility.GetCompetitionTipsType(Data.ArenaData.CompetitionData.Rule));
		};
		RewardBase component = NGUITools.AddChild(_rewardRoot, _prefabRewardDialog).GetComponent<RewardBase>();
		component.SetCardDetailUI(_cardDetailDialog);
		foreach (Wizard.Scripts.Network.Data.TaskData.Arena.Reward entryReward in data.EntryRewardList)
		{
			component.AddReward(entryReward);
		}
		component.SetActiveRewardLabel(isShow: false);
		component.SetOnlyIconEndCreate();
		base.transform.localPosition = Vector3.forward * 10f;
	}
}
