using UnityEngine;
using Wizard;

public abstract class ArenaEntryDialogBase : MonoBehaviour
{
	protected Se.TYPE _entryButtonSe = Se.TYPE.SYS_BTN_DECIDE_TRANS;

	private const int CHECK_DIALOG_DEPTH = 10;

	private ArenaEntryDataBase _entryData;

	private ArenaEntryDialogData _dialogData;

	protected ArenaData.eARENA_PAY _payType;

	public bool IsCompetition;

	protected string _mainTextId;

	protected string _ticketSpriteName;

	protected string _arenaNameTextId;

	public DialogBase ParentDialog { get; set; }

	protected abstract void Init();

	protected abstract int GetTicketNum();

	protected abstract ArenaEntryDataBase GetEntryData();

	private void Start()
	{
		Init();
		_entryData = GetEntryData();
		_dialogData = GetComponent<ArenaEntryDialogData>();
		SystemText systemText = Data.SystemText;
		if (_dialogData._mainText != null)
		{
			_dialogData._mainText.text = systemText.Get(_mainTextId);
		}
		if (_dialogData._ticketHaveTitle != null)
		{
			_dialogData._ticketHaveTitle.text = systemText.Get("Arena_0037");
			_dialogData._ticketHaveNum.text = GetTicketNum().ToString();
			_dialogData._ticketHaveUnit.text = systemText.Get("Common_0117");
			_dialogData._ticketButtonTitle.text = systemText.Get("Arena_0004");
			_dialogData._ticketButtonSubTitle.text = systemText.Get("Arena_0038");
			_dialogData._ticketButtonUseNum.text = _entryData.ticketCost.ToString();
			_dialogData._ticketSprite.spriteName = _ticketSpriteName;
			_dialogData._ticketButton.onClick.Add(new EventDelegate(delegate
			{
				if (ParentDialog.GetNowScene() == DialogBase.DialogScene.WAIT)
				{
					OnClickTicketEntryButton();
				}
			}));
		}
		if (_dialogData._rupyHaveTitle != null)
		{
			_dialogData._rupyHaveTitle.text = systemText.Get("Shop_0065");
			_dialogData._rupyHaveNum.text = PlayerStaticData.UserRupyCount.ToString();
			_dialogData._rupyHaveUnit.text = systemText.Get("Common_0120");
			_dialogData._rupyButtonTitle.text = (IsCompetition ? systemText.Get("Competition_0067") : systemText.Get("Arena_0036"));
			_dialogData._rupyButtonSubTitle.text = systemText.Get("Shop_0062");
			_dialogData._rupyButtonUseNum.text = _entryData.rupyCost.ToString();
			_dialogData._rupyButton.onClick.Add(new EventDelegate(delegate
			{
				if (ParentDialog.GetNowScene() == DialogBase.DialogScene.WAIT)
				{
					OnClickRupyEntryButton();
				}
			}));
		}
		_dialogData._crystalHaveTitle.text = systemText.Get("Shop_0064");
		_dialogData._crystalHaveNum.text = PlayerStaticData.UserCrystalCount.ToString();
		_dialogData._crystalHaveUnit.text = systemText.Get("Common_0116");
		_dialogData._crystalButtonTitle.text = (IsCompetition ? systemText.Get("Competition_0046") : systemText.Get("Arena_0023"));
		_dialogData._crystalButtonSubTitle.text = systemText.Get("Shop_0061");
		_dialogData._crystalButtonUseNum.text = _entryData.crystalCost.ToString();
		if (_entryData.ticketCost > GetTicketNum())
		{
			SetButtonDisable(_dialogData._ticketButton, _dialogData._ticketButtonTitle);
		}
		if (_entryData.rupyCost > PlayerStaticData.UserRupyCount)
		{
			SetButtonDisable(_dialogData._rupyButton, _dialogData._rupyButtonTitle);
		}
		_dialogData._crystalButton.onClick.Add(new EventDelegate(delegate
		{
			if (ParentDialog.GetNowScene() == DialogBase.DialogScene.WAIT)
			{
				OnClickCrystalEntryButton();
			}
		}));
	}

	private void SetButtonDisable(UIButton in_Button, UILabel in_Label)
	{
		in_Button.GetComponent<UIButton>().isEnabled = false;
		in_Label.color = LabelDefine.TEXT_COLOR_BUTTON_DISABLE;
		in_Button.GetComponent<TweenColor>().duration = 0f;
	}

	private void OnClickTicketEntryButton()
	{
		int ticketNum = GetTicketNum();
		SystemText systemText = Data.SystemText;
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(systemText.Get("Arena_0005"));
		dialogBase.SetPanelDepth(10);
		ArenaBuyDialog component = Object.Instantiate(_dialogData.BuyDialogObject).GetComponent<ArenaBuyDialog>();
		dialogBase.SetObj(component.gameObject);
		component.SetTicketConfirmDialog(_entryData.ticketCost, ticketNum, _arenaNameTextId, _ticketSpriteName);
		dialogBase.onPushButton1 = Entry;
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetButtonText(systemText.Get("Dia_Arena_003_Button"));
		dialogBase.ClickSe_Btn1 = _entryButtonSe;
		_payType = ArenaData.eARENA_PAY.Ticket;
	}

	private void OnClickCrystalEntryButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		if (PlayerStaticData.IsLootBoxRegulation(_entryData.LootBoxType))
		{
			LootBoxDialogUtility.CreateLootBoxRegulationDialog(_entryData.LootBoxType);
			return;
		}
		if (_entryData.crystalCost > PlayerStaticData.UserCrystalCount)
		{
			ShopCommonUtility.CreateCrystalShortagePopup();
			return;
		}
		int userCrystalCount = PlayerStaticData.UserCrystalCount;
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(systemText.Get("Arena_0005"));
		dialogBase.SetPanelDepth(10);
		ArenaBuyDialog component = Object.Instantiate(_dialogData.BuyDialogObject).GetComponent<ArenaBuyDialog>();
		dialogBase.SetObj(component.gameObject);
		component.SetClystalConfirmDialog(_entryData.crystalCost, userCrystalCount, _arenaNameTextId, _entryData.ExpirtyInfo);
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		string text_btn = (IsCompetition ? systemText.Get("Competition_0036") : systemText.Get("Dia_Arena_004_Button"));
		dialogBase.SetButtonText(text_btn);
		dialogBase.ClickSe_Btn1 = _entryButtonSe;
		dialogBase.onPushButton1 = Entry;
		_payType = ArenaData.eARENA_PAY.Crystal;
	}

	private void OnClickRupyEntryButton()
	{
		int userRupyCount = PlayerStaticData.UserRupyCount;
		SystemText systemText = Data.SystemText;
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(systemText.Get("Arena_0005"));
		dialogBase.SetPanelDepth(10);
		ArenaBuyDialog component = Object.Instantiate(_dialogData.BuyDialogObject).GetComponent<ArenaBuyDialog>();
		dialogBase.SetObj(component.gameObject);
		component.SetRupyConfirmDialog(_entryData.rupyCost, userRupyCount, _arenaNameTextId);
		dialogBase.onPushButton1 = Entry;
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		string text_btn = (IsCompetition ? systemText.Get("Competition_0036") : systemText.Get("Dia_Arena_005_Button"));
		dialogBase.SetButtonText(text_btn);
		dialogBase.ClickSe_Btn1 = _entryButtonSe;
		_payType = ArenaData.eARENA_PAY.Rupy;
	}

	protected virtual void Entry()
	{
		ParentDialog.CloseWithoutSelect();
	}
}
