using UnityEngine;

namespace Wizard;

public class GatheringEntry : MonoBehaviour
{
	private enum ViewMode
	{
		ID_INPUT,
		INVITE
	}

	[SerializeField]
	private GameObject _idInputPrefab;

	[SerializeField]
	private GameObject _entryConfirmPrefab;

	[SerializeField]
	private GameObject _receiveInviteListPrefab;

	[SerializeField]
	private UIButton _changeViewIdInputButton;

	[SerializeField]
	private UIButton _changeViewInviteButton;

	[SerializeField]
	private GameObject _activeTabSprite;

	[SerializeField]
	private GameObject _inviteBadge;

	[SerializeField]
	private UILabel[] _categoryLabel;

	private GatheringIDInput _input;

	private GatheringEntryConfirm _entryConfirm;

	private GatheringReceiveInviteList _receiveInviteList;

	public void InitializeUI()
	{
		_input = NGUITools.AddChild(base.gameObject, _idInputPrefab).GetComponent<GatheringIDInput>();
	}

	public void Initialize(GatheringGetSelfInfoTask task)
	{
		_input.OnGetInfo = OnGetEntryGetheringInfo;
		_changeViewIdInputButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickShowIdInputButton();
		}));
		_changeViewInviteButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickInviteButton();
		}));
		_inviteBadge.SetActive(task.HasInvite);
		SetViewMode(ViewMode.ID_INPUT);
	}

	private void OnGetEntryGetheringInfo(GatheringGetInfoTask task)
	{
		GameObject gameObject = Object.Instantiate(_entryConfirmPrefab);
		_entryConfirm = gameObject.GetComponent<GatheringEntryConfirm>();
		_entryConfirm.StartConfirm(task);
	}

	private void OnClickShowIdInputButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SetViewMode(ViewMode.ID_INPUT);
	}

	private void OnClickInviteButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		SetViewMode(ViewMode.INVITE);
	}

	private void SetViewMode(ViewMode mode)
	{
		if (_receiveInviteList != null)
		{
			Object.Destroy(_receiveInviteList.gameObject);
		}
		_input.gameObject.SetActive(mode == ViewMode.ID_INPUT);
		switch (mode)
		{
		case ViewMode.ID_INPUT:
			_activeTabSprite.transform.parent = _changeViewIdInputButton.transform;
			break;
		case ViewMode.INVITE:
			_activeTabSprite.transform.parent = _changeViewInviteButton.transform;
			_receiveInviteList = NGUITools.AddChild(base.gameObject, _receiveInviteListPrefab).GetComponent<GatheringReceiveInviteList>();
			_receiveInviteList.Show(this);
			break;
		}
		for (int i = 0; i < _categoryLabel.Length; i++)
		{
			if (i == (int)mode)
			{
				_categoryLabel[i].color = LabelDefine.TEXT_COLOR_NORMAL;
			}
			else
			{
				_categoryLabel[i].color = LabelDefine.TEXT_COLOR_B0B0B0;
			}
		}
		_activeTabSprite.transform.localPosition = Vector3.zero;
	}

	public void ReOpenInvite()
	{
		SetViewMode(ViewMode.INVITE);
	}

	public void UpdateInviteBadge(GatheringGetReceiveInviteTask task)
	{
		_inviteBadge.SetActive(task.InviteList.Count > 0);
	}
}
