using Cute;
using UnityEngine;

namespace Wizard;

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

	[SerializeField]
	private UIButton _stopButton;

	private const int ADDITIONAL_DIALOG_DEPTH = 15;

	private DialogBase _dialog;

	public static void Create(GameObject prefab, GatheringInfo info)
	{
		DialogBase dialog = UIManager.GetInstance().CreateDialogClose();
		Object.Instantiate(prefab).GetComponent<GatheringSettingDialog>().Initialize(info, dialog);
	}

	private void Initialize(GatheringInfo info, DialogBase dialog)
	{
		_dialog = dialog;
		dialog.SetObj(base.gameObject);
		dialog.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
		dialog.SetTitleLabel(Data.SystemText.Get("Gathering_Information_0012"));
		dialog.SetSize(DialogBase.Size.M);
		_ruleView.SetGatheringInfo(info);
	}

	private void Start()
	{
		_stopButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickStopButton();
		}));
	}

	private void OnClickStopButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		SystemText systemText = Data.SystemText;
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.RedBtn_CancelBtn);
		dialogBase.SetButtonText(systemText.Get("Gathering_Information_0018"), systemText.Get("Common_0005"));
		dialogBase.SetText(systemText.Get("Gathering_Information_0017"));
		dialogBase.SetTitleLabel(Data.SystemText.Get("Gathering_Information_0020"));
		dialogBase.SetSize(DialogBase.Size.S);
		dialogBase.SetPanelDepth(15);
		dialogBase.onPushButton1 = delegate
		{
			StopGathering();
		};
	}

	private void StopGathering()
	{
		GatheringInterruptTask task = new GatheringInterruptTask();
		StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			_dialog.SetActive(inActive: false);
			DialogBase dialogBase = UIManager.GetInstance().CreateConfirmationDialog(Data.SystemText.Get("Gathering_Information_0019"));
			dialogBase.SetPanelDepth(15);
			dialogBase.OnCloseStart = delegate
			{
				Gathering.BackToMyPageForDrop();
			};
		}));
	}
}
