using System;
using Cute;
using UnityEngine;
using Wizard;

public class BuyCrystal : MonoBehaviour
{
	public static void CreateBuyCrystal(bool isPlaySe = true, string scrollToProductId = null, bool onlyInputBirthday = false, Action onCancel = null, Action onFinish = null, bool isSpecialCrystal = false)
	{
		if (isPlaySe)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		}
		if (!onlyInputBirthday && Data.Load.data._userCrystalCount.EnableSpecialCrystal)
		{
			SpecialCrystalDialog.Create(UIManager.GetInstance().LegendCrystalBuyDialogPrefab, scrollToProductId, onCancel, onFinish);
		}
		else
		{
			InstantiateCrystalDialog(scrollToProductId, onlyInputBirthday, onCancel, onFinish, isSpecialCrystal);
		}
	}

	public static void InstantiateCrystalDialog(string scrollToProductId = null, bool onlyInputBirthday = false, Action onCancel = null, Action onFinish = null, bool isSpecialCrystal = false)
	{
		PaymentPC instance = PaymentPC.GetInstance();
		instance.initialize();
		instance.ProductListFailed += PaymentListErrorDialog;
		instance.ProductListSucceeded += delegate
		{
			OpenItemList(scrollToProductId, onlyInputBirthday, onCancel, onFinish, isSpecialCrystal);
		};
	}

	private static void CheckVideoHostingRunningAndOpenItemList(string scrollToProductid, bool onlyInputBirthday = false, Action onCancel = null, Action onFinish = null, bool isSpecialCrystal = false)
	{
		if (SingletonMonoBehaviour<VideoHostingManager>.instance.IsRecording() || SingletonMonoBehaviour<VideoHostingManager>.instance.IsPublising())
		{
			VideoHostingUtil.CreateDialogPrivacyBuyCrystalEnter(delegate
			{
				OpenItemList(scrollToProductid, onlyInputBirthday, onCancel, onFinish, isSpecialCrystal);
			});
		}
		else
		{
			OpenItemList(scrollToProductid, onlyInputBirthday, onCancel, onFinish, isSpecialCrystal);
		}
	}

	private static void OpenItemList(string scrollToProductId, bool onlyInputBirthday = false, Action onCancel = null, Action onFinish = null, bool isSpecialCrystal = false)
	{
		BuyCrystal buyCrystal = UnityEngine.Object.Instantiate(UIManager.GetInstance().BuyCrystalPrefab);
		UIManager.GetInstance().IsCrystalDialogExe = true;
		DialogBase dialog = UIManager.GetInstance().CreateDialogClose();
		dialog.SetSize(DialogBase.Size.M);
		dialog.SetTitleLabel(Data.SystemText.Get("Shop_0003"));
		dialog.SetObj(buyCrystal.gameObject);
		dialog.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialog.isNotCloseWindowButton1 = true;
		dialog.SetButtonText(Data.SystemText.Get("Dia_BuyCrystal_001_Button"));
		dialog.OnClose = delegate
		{
			if (!isSpecialCrystal || !onlyInputBirthday)
			{
				PaymentImpl.GetInstance().finalize();
			}
			if (VideoHostingUtil.IsAutoPauseRecording() || VideoHostingUtil.IsAutoPausePublishing())
			{
				VideoHostingUtil.CreateDialogPrivacyBuyCrystalExit();
			}
			UIManager.GetInstance().IsCrystalDialogExe = false;
		};
		UIManager.GetInstance().closeInSceneLoading();
		CreateItemList item_list = buyCrystal.gameObject.GetComponent<CreateItemList>();
		item_list.ParentDialogBase = dialog;
		item_list.ScrollToProductId = scrollToProductId;
		item_list.IsOnlyInputBirthday = onlyInputBirthday;
		item_list.OnFinishUpdateBirthday = delegate
		{
			onFinish.Call();
			if (onlyInputBirthday)
			{
				dialog.Close();
			}
		};
		dialog.onPushButton1 = delegate
		{
			item_list.BirthUpdateButtonClickCallBack();
		};
		dialog.onPushButton2 = delegate
		{
			item_list.BirthCancelButtonClickCallBack();
		};
		dialog.onCloseWithoutSelect = delegate
		{
			onCancel.Call();
		};
	}

	public static void PaymentListErrorDialog()
	{
		if (BattleManagerBase.GetIns() == null)
		{
			DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
			dialogBase.SetTitleLabel(Data.SystemText.Get("Shop_0094"));
			dialogBase.SetSize(DialogBase.Size.M);
			dialogBase.SetText(Data.SystemText.Get("Shop_0093"));
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
			dialogBase.SetPanelDepth(100);
		}
	}

	public void OnClickCredit()
	{
	}
}
