using Cute;
using UnityEngine;

namespace Wizard;

public class GatheringJoiningInfo : MonoBehaviour
{
	[SerializeField]
	private GatheringRuleView _ruleView;

	[SerializeField]
	private GatheringRuleView _eliminationRuleView;

	[SerializeField]
	private GameObject _root;

	[SerializeField]
	private UILabel _boardText;

	[SerializeField]
	private UIButton _editBoardButton;

	[SerializeField]
	private GameObject _editBoardInputDialogPrefab;

	[SerializeField]
	private UIButton _idCopyButton;

	[SerializeField]
	private UIButton _settingButton;

	[SerializeField]
	private GameObject _gatheringSettingDialogPrefab;

	private GatheringGetSelfInfoTask _infoTask;

	private GatheringJoining _parent;

	private void Start()
	{
		_editBoardButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickEditBoardButton();
		}));
		_idCopyButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickIdCopyButton();
		}));
		_settingButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickSettingButton();
		}));
	}

	public void Show(GatheringJoining parent)
	{
		_parent = parent;
		_root.SetActive(value: false);
		GatheringGetSelfInfoTask task = new GatheringGetSelfInfoTask(isDependGatheringInfo: true);
		UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			OnReceiveInfo(task);
		}));
	}

	private void OnReceiveInfo(GatheringGetSelfInfoTask task)
	{
		_parent.CheckChangeStatus(task.Info);
		_infoTask = task;
		bool isTournament = _infoTask.Info.Rule.IsTournament;
		_ruleView.gameObject.SetActive(!isTournament);
		_eliminationRuleView.gameObject.SetActive(isTournament);
		if (isTournament)
		{
			_eliminationRuleView.SetGatheringInfo(task.Info);
		}
		else
		{
			_ruleView.SetGatheringInfo(task.Info);
		}
		_root.SetActive(value: true);
		_boardText.text = task.Info.Description;
		bool active = task.Info.Role == GatheringRule.eRole.OWNER;
		_editBoardButton.gameObject.SetActive(active);
		_settingButton.gameObject.SetActive(active);
	}

	private void OnClickEditBoardButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		GuildInputDescriptionDialog input = Object.Instantiate(_editBoardInputDialogPrefab).GetComponent<GuildInputDescriptionDialog>();
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.S);
		dialogBase.SetTitleLabel(Data.SystemText.Get("Guild_Profile_0007"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.DecisionBtn);
		dialogBase.SetObj(input.gameObject);
		input.InputValue = _infoTask.Info.Description;
		dialogBase.onPushButton1 = delegate
		{
			UpdateBoardText(input.InputValue);
		};
	}

	private void UpdateBoardText(string text)
	{
		GatheringUpdateDescriptionTask gatheringUpdateDescriptionTask = new GatheringUpdateDescriptionTask();
		gatheringUpdateDescriptionTask.SetParameter(text);
		StartCoroutine(Toolbox.NetworkManager.Connect(gatheringUpdateDescriptionTask, delegate
		{
			DialogBase dialogBase = UIManager.GetInstance().CreateConfirmationDialog(Data.SystemText.Get("Guild_Profile_0010"));
			dialogBase.onPushButton1 = delegate
			{
				_parent.ReOpenCurrentCategory();
			};
			dialogBase.onCloseWithoutSelect = delegate
			{
				_parent.ReOpenCurrentCategory();
			};
		}));
	}

	private void OnClickIdCopyButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		NativePluginWrapper.SetStringToClipboard(_infoTask.Info.Id);
		UIManager.GetInstance().CreateConfirmationDialog(Data.SystemText.Get("Gathering_Information_0011"));
	}

	private void OnClickSettingButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		GatheringSettingDialog.Create(_gatheringSettingDialogPrefab, _infoTask.Info);
	}
}
