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

public class SpecialCrystalBuyFinishDialog : MonoBehaviour
{
	[SerializeField]
	private UILabel _label;

	[SerializeField]
	private UITexture _tipsTexture;

	[SerializeField]
	private GameObject _begginerRoot;

	[SerializeField]
	private UIButton _goToShopButton;

	[SerializeField]
	private UIButton _goToShopButton2;

	[SerializeField]
	private UILabel _nextSceneLabel;

	private List<string> _assetList = new List<string>();

	private SpecialCrystalInfo _specialCrystalInfo;

	private DialogBase _dialog;

	private string _productName;

	private static bool NeedExtraResultDialog(SpecialCrystalInfo info)
	{
		if (!info.EnableExtraResult)
		{
			return false;
		}
		return info.ExtraResultPurchaseCount == info.AvailablePurchaseCount;
	}

	public static void Create(GameObject prefab, SpecialCrystalInfo info, string productName)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		SystemText systemText = Data.SystemText;
		dialogBase.SetTitleLabel(systemText.Get("MyPage_0051"));
		if (NeedExtraResultDialog(info))
		{
			SpecialCrystalBuyFinishDialog component = Object.Instantiate(prefab).GetComponent<SpecialCrystalBuyFinishDialog>();
			dialogBase.SetSize(DialogBase.Size.M);
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
			dialogBase.onPushButton1 = delegate
			{
				ReloadMyPage();
			};
			dialogBase.SetObj(component.gameObject);
			component._dialog = dialogBase;
			component._specialCrystalInfo = info;
			component._productName = productName;
		}
		else
		{
			dialogBase.SetSize(DialogBase.Size.S);
			if (info.Status.StartsWith("80"))
			{
				dialogBase.SetText(Data.SystemText.Get("MyPage_0116", productName));
			}
			else
			{
				dialogBase.SetText(Data.SystemText.Get("MyPage_0059", productName));
			}
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
			dialogBase.onPushButton1 = delegate
			{
				ReloadMyPage();
			};
		}
		dialogBase.onCloseWithoutSelect = delegate
		{
			ReloadMyPage();
		};
	}

	public static void ReloadMyPage()
	{
		if (UIManager.GetInstance().GetCurrentScene() == UIManager.ViewScene.MyPage)
		{
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage);
		}
	}

	private IEnumerator Start()
	{
		_label.text = Data.SystemText.Get("MyPage_0059", _productName);
		_nextSceneLabel.text = SceneTransition.TransitionData.GetTransitionText(_specialCrystalInfo.ResultDialogNextSceneClick);
		ResourcesManager resourceManager = Toolbox.ResourcesManager;
		string assetTypePath = Toolbox.ResourcesManager.GetAssetTypePath(_specialCrystalInfo.ExtraResultDialogBGImageFileName, ResourcesManager.AssetLoadPathType.SpecialCrystal);
		_assetList.Add(assetTypePath);
		yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetAsync(assetTypePath, null));
		_tipsTexture.mainTexture = resourceManager.LoadObject(resourceManager.GetAssetTypePath(_specialCrystalInfo.ExtraResultDialogBGImageFileName, ResourcesManager.AssetLoadPathType.SpecialCrystal, isfetch: true)) as Texture;
		UIEventListener.Get(_goToShopButton.gameObject).onClick = delegate
		{
			OnClickNextSceneButton();
		};
		UIEventListener.Get(_goToShopButton2.gameObject).onClick = delegate
		{
			OnClickNextSceneButton();
		};
	}

	private void OnDestroy()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_assetList);
		_assetList.Clear();
	}

	private void OnClickNextSceneButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		MyPageBannerBase.SceneChangeBySetting(_specialCrystalInfo.ResultDialogNextSceneClick, _specialCrystalInfo.ResultDialogNextSceneStatus);
		_dialog.Close();
	}
}
