using System;
using System.Collections.Generic;
using Cute;
using UnityEngine;
using Wizard.Dialog.Setting;
using Wizard.Scripts.Network.Task.ItemAcquireHistory;
using Wizard.UI.Dialog;

namespace Wizard;

public class MyPageOtherButtons : UIBase
{
	[SerializeField]
	private GameObject _dialogNotificationMenu;

	[SerializeField]
	private GameObject _dialogContactMenu;

	[SerializeField]
	private GameObject _dialogRewardScroll;

	[SerializeField]
	private GameObject _dialogUserTicketCountPrefab;

	[SerializeField]
	private UILabel _labelVideoHosting;

	[SerializeField]
	private GameObject _buttonPool;

	[SerializeField]
	private UIGrid _girdButtons;

	[SerializeField]
	private UIButton _btnProfile;

	[SerializeField]
	private UIButton _btnFriend;

	[SerializeField]
	private UIButton _btnRanking;

	[SerializeField]
	private GameObject _achievementIcon;

	[SerializeField]
	private GameObject _achievementIconAndroid;

	[SerializeField]
	private UIButton _btnSetting;

	[SerializeField]
	private UIButton _btnReplay;

	[SerializeField]
	private UIButton _btnHelp;

	[SerializeField]
	private UIButton _btnGameGuide;

	[SerializeField]
	private UIButton _btnItemsHistory;

	[SerializeField]
	private UIButton _btnAchievement;

	[SerializeField]
	private UIButton _btnData;

	[SerializeField]
	private UIButton _btnAccountConnect;

	[SerializeField]
	private UIButton _btnContact;

	[SerializeField]
	private UIButton _btnNotification;

	[SerializeField]
	private UIButton _btnSwitchLanguage;

	[SerializeField]
	private UIButton _btnVideoHosting;

	[SerializeField]
	private UIButton _btnCodeInput;

	[SerializeField]
	private UIButton _btnReturnTitle;

	[SerializeField]
	private UIButton _btnPortalSite;

	[SerializeField]
	private UIButton _btnOffcialSite;

	[SerializeField]
	private UIButton _btnSignInOut;

	[SerializeField]
	private UIButton _btnTicketCount;

	[SerializeField]
	private UIButton _informationButton;

	[SerializeField]
	private GameObject _adjustSettingDialogPrefab;

	[SerializeField]
	private UIButton _btnAdjustSetting;

	[SerializeField]
	private UILabel _btnSignInOutLabel;

	private const int CODE_NUMBER_MAX = 16;

	private DialogBase _dialogCodeInput;

	private UIInput _codeInput;

	[SerializeField]
	private UILabel _friendBadgeLabel;

	[SerializeField]
	private UIButton _smallResourceButton;

	public List<UIButton> _enableOtherButtons { get; private set; }

	public UIButton btnAchievement => _btnAchievement;

	public UILabel FriendBadgeLabel => _friendBadgeLabel;

	public UIButton FriendButton => _btnFriend;

	private void Start()
	{
		_labelVideoHosting.text = VideoHostingUtil.GetVideoHostingSettingTitle();
	}

	public void Init()
	{
		List<UIButton> list = new List<UIButton>();
		list.Add(_btnSetting);
		list.Add(_btnReplay);
		list.Add(_btnHelp);
		list.Add(_informationButton);
		list.Add(_btnGameGuide);
		list.Add(_btnTicketCount);
		list.Add(_btnItemsHistory);
		list.Add(_btnNotification);
		list.Add(_btnData);
		list.Add(_btnContact);
		list.Add(_btnPortalSite);
		list.Add(_btnOffcialSite);
		list.Add(_btnSwitchLanguage);
		list.Add(_btnCodeInput);
		list.Add(_btnAdjustSetting);
		list.Add(_btnReturnTitle);
		for (int i = 0; i < list.Count; i++)
		{
			list[i].transform.parent = _girdButtons.transform;
		}
		if (_enableOtherButtons == null)
		{
			_enableOtherButtons = new List<UIButton>();
		}
		_enableOtherButtons.Clear();
		_enableOtherButtons.Add(_btnProfile);
		_enableOtherButtons.Add(_btnFriend);
		_enableOtherButtons.Add(_btnRanking);
		_enableOtherButtons.AddRange(list);
		for (int j = 0; j < _enableOtherButtons.Count; j++)
		{
			_enableOtherButtons[j].gameObject.SetActive(value: true);
		}
		base.gameObject.SetActive(value: true);
		_girdButtons.Reposition();
		_girdButtons.enabled = false;
		_buttonPool.SetActive(value: false);
		_btnAdjustSetting.onClick.Clear();
		_btnAdjustSetting.onClick.Add(new EventDelegate(delegate
		{
			OnClickAdjustSetting();
		}));
		_informationButton.onClick.Clear();
		_informationButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickInformation();
		}));
		_smallResourceButton.onClick.Clear();
		_smallResourceButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickSmallResourceButton();
		}));
	}

	private void OnClickSmallResourceButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		int beforeSetting = PlayerPrefsCache.Instance.GetValue(PlayerPrefsWrapper.SMALL_RESOURCE_STATUS);
		Action onFinish = delegate
		{
			int value = PlayerPrefsCache.Instance.GetValue(PlayerPrefsWrapper.SMALL_RESOURCE_STATUS);
			if (beforeSetting != value)
			{
				SoftwareReset.exec();
			}
		};
		Action onCancel = delegate
		{
		};
		SmallResourceSelectDialog.Create(onFinish, onCancel, isTitle: false);
	}

	private void OnClickInformation()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		CheckTimeSlipRotationPeriodTask task = new CheckTimeSlipRotationPeriodTask();
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			UIManager.GetInstance().WebViewHelper.OpenWebView(WebViewHelper.WebViewType.INFO);
		}));
	}

	private void UpdateSignInOutText()
	{
		if (!(_btnSignInOutLabel == null))
		{
			SystemText systemText = Data.SystemText;
			if (SocialServiceUtility.Instance.IsLoggedIn)
			{
				_btnSignInOutLabel.text = systemText.Get("OtherTop_0036");
			}
			else
			{
				_btnSignInOutLabel.text = systemText.Get("OtherTop_0035");
			}
		}
	}

	protected override void OnDestroy()
	{
		base.OnDestroy();
	}

	public void OnBtnProfile()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Profile);
	}

	public void OnBtnFriend()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Friend);
	}

	public void OnBtnRanking()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Ranking);
	}

	public void OnBtnSetting()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SettingBase.CreateDialog();
	}

	public void OnBtnReplay()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		ReplayInfoTask replayInfoTask = new ReplayInfoTask();
		replayInfoTask.SetParameter();
		StartCoroutine(Toolbox.NetworkManager.Connect(replayInfoTask, delegate
		{
			ReplayDialog.Create();
		}));
	}

	public void OnBtnHelp()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().WebViewHelper.OpenWebView(WebViewHelper.WebViewType.HELP);
	}

	public void OnBtnGameGuide()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().WebViewHelper.CreateOpenURLWindow(WebViewHelper.UrlType.GAME_GUIDE);
	}

	public void OnBtnUserTicketCount()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("OtherTop_0062"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		UserTicketCountDialog component = UnityEngine.Object.Instantiate(_dialogUserTicketCountPrefab).GetComponent<UserTicketCountDialog>();
		component.Init(dialogBase);
		dialogBase.SetObj(component.gameObject);
	}

	public void OnBtnItemHistory()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		ItemAcquireHistoryInfoTask itemAcquireHistoryInfoTask = new ItemAcquireHistoryInfoTask();
		itemAcquireHistoryInfoTask.SetParameter();
		StartCoroutine(Toolbox.NetworkManager.Connect(itemAcquireHistoryInfoTask, _DisplayItemHistory, BaseTask.OnRequestFailed, BaseTask.OnFailedErrorCode));
	}

	public void OnBtnAchievement()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		VideoHostingUtil.CheckVideoHostingAndShowAchievement(delegate
		{
			AchievementImpl.instance.ShowAchievements(delegate
			{
				UpdateSignInOutText();
			});
		});
	}

	public void OnBtnData()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		if (SingletonMonoBehaviour<VideoHostingManager>.instance.IsRecording() || SingletonMonoBehaviour<VideoHostingManager>.instance.IsPublising())
		{
			VideoHostingUtil.CreateDialogPrivacyAccount();
		}
		else
		{
			CreateDataLinkDialog();
		}
	}

	public static void CreateDataLinkDialog()
	{
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		EventDelegate method_btn = new EventDelegate(delegate
		{
			UIManager.GetInstance().AccountTransferHelper.CreateAccountTransferDialog(AccountBase.DisplayType.OTHER, AccountBase.TransitionOriginalScreen.OTHER);
		});
		dialogBase.SetButtonDelegate(method_btn);
		dialogBase.SetTitleLabel(systemText.Get("Account_0001"));
		dialogBase.SetButtonText(systemText.Get("Account_0089"));
		string text = systemText.Get("Account_0098");
		dialogBase.SetText(text);
		dialogBase.SetSize(DialogBase.Size.M);
	}

	public void OnBtnAccountConnect()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		if (SingletonMonoBehaviour<VideoHostingManager>.instance.IsRecording() || SingletonMonoBehaviour<VideoHostingManager>.instance.IsPublising())
		{
			VideoHostingUtil.CreateDialogPrivacyAccount();
		}
		else
		{
			CreateDialogAccountLink();
		}
	}

	public static void CreateDialogAccountLink(Action close_callback = null)
	{
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		EventDelegate method_btn = new EventDelegate(delegate
		{
			UIManager.GetInstance().AccountTransferHelper.CreateAccountTransferDialog(AccountBase.DisplayType.ACCOUNT_LINK, AccountBase.TransitionOriginalScreen.OTHER, close_callback);
		});
		dialogBase.SetTitleLabel(systemText.Get("Account_0087"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetButtonText(systemText.Get("Account_0084"));
		dialogBase.SetButtonDelegate(method_btn);
		string text = systemText.Get("Account_0083");
		dialogBase.SetText(text);
		dialogBase.SetSize(DialogBase.Size.M);
	}

	public void OnBtnContactSupport()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Con_Management_001_Title"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		GameObject gameObject = UnityEngine.Object.Instantiate(_dialogContactMenu);
		gameObject.GetComponent<DialogContactMenu>().SetDialog(dialogBase);
		dialogBase.SetObj(gameObject);
	}

	public void OnBtnNotification()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(Data.SystemText.Get("OtherTop_0014"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		GameObject obj = UnityEngine.Object.Instantiate(_dialogNotificationMenu);
		dialogBase.SetObj(obj);
	}

	public void OnBtnSwitchLanguage()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SwitchLanguage.Create(isForceConfirmDialog: false, isTitle: false, delegate(bool isChangeLanguage)
		{
			if (isChangeLanguage)
			{
				Toolbox.SavedataManager.SetString(SavedataManager.LANGUAGE_CHANGE, "TRUE");
			}
			SoftwareReset.exec();
		});
	}

	public void OnBtnReturnTitle()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SystemText systemText = Data.SystemText;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(systemText.Get("OtherTop_0026"));
		dialogBase.SetText(systemText.Get("OtherTop_0027"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetButtonText(systemText.Get("OtherTop_0028"));
		dialogBase.onPushButton1 = delegate
		{
			SoftwareReset.exec();
		};
	}

	public void OnBtnVideoHosting()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		ActivateVideoHosting();
	}

	private void ActivateVideoHosting()
	{
		if (SingletonMonoBehaviour<VideoHostingManager>.instance.IsVideoHostingSupported())
		{
			VideoHostingUtil.CreateVideoHostingSetting();
		}
		else
		{
			VideoHostingUtil.CreateDialogNotSupported();
		}
	}

	public void OnBtnPortalSite()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.ShowDialogUrl(Data.SystemText.Get("OtherTop_0030"), Data.SystemText.Get("URL_0002"));
	}

	public void OnBtnOffcialSite()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SystemText systemText = Data.SystemText;
		string text = "URL_0014";
		text += "_steam";
		UIManager.ShowDialogUrl(systemText.Get("OtherTop_0031"), systemText.Get(text));
	}

	public void OnBtnCodeInput()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		_dialogCodeInput = InputDialog.Create(16, 16);
		_dialogCodeInput.InputAreaObjs.labels[2].text = Data.SystemText.Get("OtherCode_0009");
		_dialogCodeInput.InputAreaObjs.labels[3].text = "";
		_dialogCodeInput.SetTitleLabel(Data.SystemText.Get("OtherCode_0005"));
		_dialogCodeInput.onPushButton1 = ReturnCodeInput;
		_dialogCodeInput.SetButtonDisable(isEnableOK: true);
		_codeInput = _dialogCodeInput.GetComponentInChildren<UIInput>();
		_codeInput.onChange.Add(new EventDelegate(OnChangeCodeInput));
	}

	private void OnChangeCodeInput()
	{
		_dialogCodeInput.SetButtonDisable(_codeInput.value.Length < 16);
	}

	private void ReturnCodeInput()
	{
		string text = _dialogCodeInput.InputAreaObjs.labels[0].text;
		MyPageCodeInputTask task = new MyPageCodeInputTask();
		task.SetParameter(text);
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate(NetworkTask.ResultCode errorCode)
		{
			OnSuccessCodeInput(errorCode, task);
		}));
	}

	private void OnSuccessCodeInput(NetworkTask.ResultCode errorcode, MyPageCodeInputTask inputTask)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(Data.SystemText.Get("OtherCode_0011"));
		if (inputTask.IsComplete)
		{
			dialogBase.SetText(Data.SystemText.Get("OtherCode_0012"));
		}
		else
		{
			dialogBase.SetText(Data.SystemText.Get("OtherCode_0010"));
		}
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.onPushButton1 = delegate
		{
			MailTopTask mailTopTask = GameMgr.GetIns().GetMailTopTask();
			mailTopTask.SetParameter(isTutorial: false);
			StartCoroutine(Toolbox.NetworkManager.Connect(mailTopTask, delegate
			{
				UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Mail);
			}));
		};
	}

	public void OnBtnShutdown()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		Application.Quit();
	}

	public void OnBtnSignInOut()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SystemText text = Data.SystemText;
		try
		{
			if (SocialServiceUtility.Instance.IsLoggedIn)
			{
				SocialServiceUtility.Instance.SignOut(delegate
				{
					_btnSignInOutLabel.text = text.Get("OtherTop_0035");
					PlayerPrefsWrapper.SetBool(PlayerPrefsWrapper.SOCIAL_ACHIEVEMENT_SIGNIN, flag: false);
				});
				return;
			}
			StartCoroutine(SocialServiceUtility.Instance.SignIn(delegate(bool success)
			{
				if (success)
				{
					_btnSignInOutLabel.text = text.Get("OtherTop_0036");
					PlayerPrefsWrapper.SetBool(PlayerPrefsWrapper.SOCIAL_ACHIEVEMENT_SIGNIN, flag: true);
				}
			}));
		}
		catch (Exception ex)
		{
			LocalLog.AccumulateTraceLog("サインイン・アウト処理失敗：" + ex);
		}
	}

	private void _DisplayItemHistory(NetworkTask.ResultCode result)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Mail_0050"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		UIManager.GetInstance().closeInSceneCenterLoading();
		GameObject gameObject = UnityEngine.Object.Instantiate(_dialogRewardScroll);
		dialogBase.SetObj(gameObject);
		DialogRewardScroll component = gameObject.GetComponent<DialogRewardScroll>();
		ResourceHandler resourceHandler = base.gameObject.AddMissingComponent<ResourceHandler>();
		component.Handler = resourceHandler;
		component.CurrentList = Data.ItemAcquireHistoryInfo.Histories;
		component.resetScrollWrap();
		dialogBase.OnClose = delegate
		{
			resourceHandler.UnloadAll();
			UnityEngine.Object.Destroy(resourceHandler);
		};
	}

	private void OnClickAdjustSetting()
	{
		AdjustSendSettingDialog.Create(_adjustSettingDialogPrefab).OnChange = delegate(bool enable)
		{
			AdjustSettingUpdateTask adjustSettingUpdateTask = new AdjustSettingUpdateTask();
			adjustSettingUpdateTask.SetParameter(enable);
			StartCoroutine(Toolbox.NetworkManager.Connect(adjustSettingUpdateTask, delegate
			{
				Data.Load.data._userConfig.SetArrowAdjustSend(enable);
			}));
		};
	}
}
