using Cute;
using Wizard.ErrorDialog;

namespace Wizard;

public class NetworkUI : INetworkUI
{
	private static NetworkUI instance;

	private DialogBase _errorDialog;

	private const int DEAPTH = 6000;

	private const int PC_ERROR_NEW_VERSION_AVAILABLE = 214;

	public bool keepLastRequest;

	public static NetworkUI GetInstance()
	{
		if (instance == null)
		{
			instance = new NetworkUI();
		}
		return instance;
	}

	public NetworkUI()
	{
		keepLastRequest = false;
	}

	public bool IsKeepLastRequest()
	{
		return keepLastRequest;
	}

	public void SetKeepLastRequest(bool flag)
	{
		keepLastRequest = flag;
	}

	public void StartLoading(bool notEditor)
	{
		if (notEditor)
		{
			UIManager.GetInstance().createInSceneCenterLoading(notBlack: true, notCollider: false, force: false);
		}
		else
		{
			UIManager.GetInstance().createInSceneCenterLoading(notBlack: true, notCollider: false, force: false);
		}
	}

	public void StopLoading()
	{
		UIManager.GetInstance().closeInSceneCenterLoading(force: false);
	}

	public string GetText(string code)
	{
		string text = "";
		text = Data.SystemText.Get(code);
		if (string.IsNullOrEmpty(text))
		{
			text = code;
		}
		return text;
	}

	public void GoToMypage()
	{
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage);
	}

	public void SoftwareRest()
	{
		SoftwareReset.exec();
	}

	public void OpenRetryAndToTitleErrorPopUp(string title, string message, string errorCode)
	{
		if (!keepLastRequest)
		{
			keepLastRequest = true;
			UIManager.GetInstance().closeInSceneCenterLoading();
			DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose(isSystem: true);
			dialogBase.SetFadeButtonEnabled(flag: false);
			dialogBase.SetSize(DialogBase.Size.M);
			dialogBase.SetPanelDepth(6000);
			dialogBase.SetTitleLabel(title);
			dialogBase.SetText(message);
			dialogBase.SetReturnMsg(Toolbox.NetworkManager.gameObject, "Retry", "ReturnToTitle");
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_GrayBtn);
			dialogBase.SetButtonText(GetText("System_0012"), GetText("System_0006"));
			dialogBase.ClickSe_Btn2 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
			dialogBase.SetVisibleContactButton(isVisible: true, errorCode);
			dialogBase.OnClose = delegate
			{
				keepLastRequest = false;
			};
		}
	}

	public void OpenGoToMypageErrorPopUp(string title, string message, string errorCode)
	{
		if (!keepLastRequest)
		{
			keepLastRequest = true;
			UIManager.GetInstance().closeInSceneCenterLoading();
			DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose(isSystem: true);
			dialogBase.SetFadeButtonEnabled(flag: false);
			dialogBase.SetSize(DialogBase.Size.M);
			dialogBase.SetPanelDepth(6000);
			dialogBase.SetTitleLabel((title == "") ? GetText("Error_0002") : title);
			dialogBase.SetText((message == "") ? GetText("System_0011") : message);
			dialogBase.SetReturnMsg(Toolbox.NetworkManager.gameObject, "GoToMypage");
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.GrayBtn);
			dialogBase.SetButtonText(GetText("System_0010"));
			dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
			dialogBase.SetVisibleContactButton(isVisible: true, errorCode);
			dialogBase.OnClose = delegate
			{
				keepLastRequest = false;
			};
			_errorDialog = dialogBase;
		}
	}

	public void OpenGoToTitleErrorPopUp(string title, string message, string errorCode)
	{
		keepLastRequest = false;
		UIManager.GetInstance().closeInSceneCenterLoading();
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose(isSystem: true);
		dialogBase.SetFadeButtonEnabled(flag: false);
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetPanelDepth(6000);
		dialogBase.SetTitleLabel(title);
		dialogBase.SetText(message);
		dialogBase.SetReturnMsg(Toolbox.NetworkManager.gameObject, "ReturnToTitle");
		if (title == GetText("System_0022"))
		{
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		}
		else
		{
			dialogBase.SetButtonLayout(DialogBase.ButtonLayout.GrayBtn);
			dialogBase.SetButtonText(GetText("System_0006"));
			dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
		}
		dialogBase.SetVisibleContactButton(isVisible: true, errorCode);
		_errorDialog = dialogBase;
	}

	public void OpenCloseOnlyErrorPopUp(int resultCode)
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(resultCode);
	}

	public void OpenAccountBlockErrorPopUp(int resultCode)
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(resultCode);
	}

	public void OpenAccountLimitedBlockErrorPopUp(int resultCode, string endTimeText)
	{
		SystemText systemText = Data.SystemText;
		Wizard.ErrorDialog.Data data = Wizard.ErrorDialog.Dialog.FindData(resultCode);
		DialogBase dialogBase = Wizard.ErrorDialog.Dialog.Create(resultCode);
		dialogBase.SetText(systemText.Get(data.BodyId, ConvertTime.ToLocal(endTimeText)));
		_errorDialog = dialogBase;
	}

	public void OpenOtherServerErrorPopUp(int resultCode)
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(resultCode);
	}

	public void OpenGotoStoreErrorPopup()
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(214);
	}

	public void OpenRetryFailErrorPopup()
	{
		keepLastRequest = false;
		UIManager.GetInstance().CreatFadeOpen();
		UIManager.GetInstance().closeInSceneCenterLoading();
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetFadeButtonEnabled(flag: false);
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetPanelDepth(6000);
		dialogBase.SetTitleLabel(GetText("Error_0002"));
		dialogBase.SetText(GetText("System_0018"));
		dialogBase.SetReturnMsg(Toolbox.NetworkManager.gameObject, "ReturnToTitle");
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.GrayBtn);
		dialogBase.SetButtonText(GetText("System_0006"));
		dialogBase.ClickSe_Btn1 = Se.TYPE.SYS_BTN_CANCEL_TRANS;
		_errorDialog = dialogBase;
	}

	public void OpenTimeOutErrorPopUp()
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create("TIMEOUT");
	}

	public void OpenHttpStatusErrorPopUp()
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create("COMMUNICATION");
	}

	public void OpenResourceVersionUpPopUp()
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create("RES_VERSION_UP");
	}

	public void OpenSessionErrorPopUp()
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(201);
	}

	public bool isCloseDialogGroupError(int resultCode)
	{
		return NetworkDefine.IsCloseOnlyDialogError(resultCode);
	}

	public void OpenAllMaintenancePopUp(int resultCode, string endTime)
	{
		SystemText systemText = Data.SystemText;
		if (string.IsNullOrEmpty(endTime))
		{
			Wizard.ErrorDialog.Data data = Wizard.ErrorDialog.Dialog.FindData("URGENCY_MAINTENANCE");
			DialogBase dialogBase = Wizard.ErrorDialog.Dialog.Create("URGENCY_MAINTENANCE");
			dialogBase.SetText(systemText.Get(data.BodyId, systemText.Get("Common_0118")));
			_errorDialog = dialogBase;
		}
		else
		{
			Wizard.ErrorDialog.Data data2 = Wizard.ErrorDialog.Dialog.FindData(resultCode);
			DialogBase dialogBase2 = Wizard.ErrorDialog.Dialog.Create(resultCode);
			dialogBase2.SetText(systemText.Get(data2.BodyId, ConvertTime.ToLocal(endTime)));
			_errorDialog = dialogBase2;
		}
	}

	public void OpenStrictServerErrorPopUp(int resultCode)
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(resultCode);
	}

	public void OpenEachFunctionMaintenancePopUp(int resultCode)
	{
		_errorDialog = Wizard.ErrorDialog.Dialog.Create(resultCode);
	}

	public void OpenSocialServiceNoResponseErrorPopup()
	{
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = Wizard.ErrorDialog.Dialog.Create("SOCIAL_SERVICE_NO_RESPONSE");
		string socialServiceName = SocialServiceUtility.GetSocialServiceName();
		Wizard.ErrorDialog.Data data = Wizard.ErrorDialog.Dialog.FindData("SOCIAL_SERVICE_NO_RESPONSE");
		dialogBase.SetText(systemText.Get(data.BodyId, socialServiceName));
		_errorDialog = dialogBase;
	}

	public bool IsOpenErrorDialog()
	{
		return _errorDialog != null;
	}

	public void CloseErrorDialog()
	{
		if (_errorDialog != null)
		{
			_errorDialog.Close();
		}
		_errorDialog = null;
	}
}
