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

public class PaymentUI
{
	public IEnumerator GooglePlayPointRewardFinished(string message)
	{
		yield return new WaitForSeconds(0.5f);
		while (Toolbox.NetworkManager.isConnect || Toolbox.NetworkManager.isTimeOut || Toolbox.NetworkManager.isError || UIManager.GetInstance().isOpenDialog())
		{
			yield return 0;
		}
		createNewDialog(Wizard.Data.SystemText.Get("Common_0021"), message);
	}

	public void PurchaseFinished(string name = "", int amount = 0, int sum = 0, bool isRefundedReceipt = false)
	{
		if (string.IsNullOrEmpty(name))
		{
			name = Wizard.Data.SystemText.Get("Common_0201");
		}
		string message = Wizard.Data.SystemText.Get("Shop_0022", name);
		if (amount != 0)
		{
		}
		if (!isRefundedReceipt)
		{
			createNewDialog("", message);
		}
	}

	public void PurchaseFailed(string name = "", int amount = 0, int sum = 0)
	{
		SystemText systemText = Wizard.Data.SystemText;
		string title = systemText.Get("Shop_0025");
		string message = systemText.Get("Shop_0084");
		createNewDialog(title, message);
	}

	public void PurchaseCancelled(string name = "", int amount = 0, int sum = 0)
	{
		SystemText systemText = Wizard.Data.SystemText;
		string title = systemText.Get("Shop_0025");
		string message = systemText.Get("Shop_0085");
		createNewDialog(title, message);
	}

	public void PurchaseTimeOut(string message = "", string title = "", DialogBase.Size size = DialogBase.Size.M)
	{
		if (BattleManagerBase.GetIns() == null)
		{
			SystemText systemText = Wizard.Data.SystemText;
			if (string.IsNullOrEmpty(title))
			{
				title = systemText.Get("Shop_0025");
			}
			if (string.IsNullOrEmpty(message))
			{
				message = systemText.Get("Shop_0086");
			}
			createNewDialog(title, message, size);
		}
	}

	public void ProductListInitTimeOut()
	{
		if (BattleManagerBase.GetIns() == null)
		{
			SystemText systemText = Wizard.Data.SystemText;
			string title = systemText.Get("Shop_0094");
			string message = systemText.Get("Shop_0093");
			createNewDialog(title, message, DialogBase.Size.M);
		}
	}

	public void StartLoading(bool useTimeCount = false, bool forProductListInit = false)
	{
		if (useTimeCount)
		{
			PaymentImpl.GetInstance().StartTimeCount(forProductListInit);
		}
		UIManager.GetInstance().createInSceneCenterLoading();
	}

	public void StopLoading()
	{
		PaymentImpl.GetInstance().StopTimeCount();
		UIManager.GetInstance().closeInSceneCenterLoading();
	}

	private static void createNewDialog(string title, string message, DialogBase.Size size = DialogBase.Size.S)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		if (title != "")
		{
			dialogBase.SetTitleLabel(title);
		}
		dialogBase.SetText(message);
		dialogBase.SetSize(size);
		dialogBase.SetPanelDepth(3000);
	}

	public string GetText(string text_id)
	{
		return Wizard.Data.SystemText.Get(text_id);
	}

	public void PurchaseConfirm(string productId, string name = "", int amount = 0, int sum = 0)
	{
		if (string.IsNullOrEmpty(name))
		{
			name = Wizard.Data.SystemText.Get("Common_0201");
		}
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		string text = "";
		if (amount <= sum)
		{
			text = Wizard.Data.SystemText.Get("Shop_0110", name, sum.ToString());
			dialogBase.SetButtonDelegate(new EventDelegate(delegate
			{
				PaymentPC.GetInstance().purchaceFinish(productId);
			}));
		}
		else
		{
			text = Wizard.Data.SystemText.Get("Shop_0111", name, sum.ToString());
			dialogBase.SetButtonDelegate(new EventDelegate(delegate
			{
				BrowserURL.Open("https://point.dmm.com/choice/pay");
			}));
		}
		dialogBase.SetText(text);
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetTitleLabel(Wizard.Data.SystemText.Get("Shop_0003"));
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetPanelDepth(3000);
	}

	public void PurchaseFailedPC(NetworkTask.ResultCode resultCode)
	{
		if (resultCode == NetworkTask.ResultCode.TimeOut)
		{
			DialogBase dialogBase = Dialog.Create("TIMEOUT_NORETRY");
			SystemText systemText = Wizard.Data.SystemText;
			dialogBase.SetTitleLabel(systemText.Get("ErrorHeader_0012"));
			dialogBase.SetText(systemText.Get("Error_0006"));
		}
	}
}
