using System;
using System.Collections;
using Cute;
using UnityEngine;

namespace Wizard;

public class Gathering : UIBase
{
	[SerializeField]
	private GatheringEntry _entryRoot;

	[SerializeField]
	private GatheringJoining _joiningRoot;

	public override void onFirstStart()
	{
		_entryRoot.InitializeUI();
		_joiningRoot.InitializeUI();
		_entryRoot.gameObject.SetActive(value: false);
		_joiningRoot.gameObject.SetActive(value: false);
		base.IsShowFooterMenu = true;
		base.onFirstStart();
		Data.MyPageNotifications.data.GatheringMyPageInfo.IsMatchingNotification = false;
		if (Data.MyPage.data != null)
		{
			UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
		}
		GatheringGetSelfInfoTask task = new GatheringGetSelfInfoTask(isDependGatheringInfo: false);
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			Initialize(task);
		}));
	}

	private UIManager.ChangeViewSceneParam CreateBackButtonParam()
	{
		return new UIManager.ChangeViewSceneParam
		{
			MyPageMenuIndex = 3,
			OnFinishChangeView = delegate
			{
				MyPageMenu.Instance.GoToGatheringActionMenu();
			}
		};
	}

	public static void BackToMyPageForDrop()
	{
		UIManager.ChangeViewSceneParam changeViewSceneParam = new UIManager.ChangeViewSceneParam();
		changeViewSceneParam.MyPageMenuIndex = 3;
		changeViewSceneParam.OnFinishChangeView = delegate
		{
			MyPageMenu.Instance.GoToGatheringActionMenu();
		};
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage, changeViewSceneParam);
	}

	private void Initialize(GatheringGetSelfInfoTask task)
	{
		GatheringInfo info = task.Info;
		string titleMsg;
		if (info.Role == GatheringRule.eRole.NONE)
		{
			_entryRoot.Initialize(task);
			titleMsg = Data.SystemText.Get("Gathering_0002");
		}
		else
		{
			_joiningRoot.Initialize();
			titleMsg = Data.SystemText.Get("Gathering_0034");
		}
		_entryRoot.gameObject.SetActive(info.Role == GatheringRule.eRole.NONE);
		_joiningRoot.gameObject.SetActive(info.Role != GatheringRule.eRole.NONE);
		_joiningRoot.OnReceiveSelfInfo(info);
		UIManager.GetInstance().CreateTopBar(base.gameObject, titleMsg, UIManager.ViewScene.MyPage, MoneyDraw: true, CreateBackButtonParam()).gameObject.layer = LayerMask.NameToLayer("MyPage");
		StartCoroutine(WaitForCommonBackGround(delegate
		{
			UIManager.GetInstance().OnReadyViewScene(isFadein: true);
		}));
	}

	private IEnumerator WaitForCommonBackGround(Action onComplete)
	{
		while (!CommonBackGround.Instance.IsFinishLod)
		{
			yield return null;
		}
		while (!CommonBackGround.Instance.IsFinishEffectLoading())
		{
			yield return null;
		}
		onComplete?.Invoke();
	}

	public override bool IsUseCommonBackground()
	{
		return true;
	}
}
