using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class TransitionDialog : MonoBehaviour
{
	[SerializeField]
	private UIToggle _toggle;

	[SerializeField]
	private UIScrollView _scrollView;

	[SerializeField]
	private UILabel _coutionLabel;

	[SerializeField]
	private UILabel _coutionTitleLabel;

	private Action _completePublishTransitionCode;

	private bool _firstToggleCall = true;

	public Action<bool> OnChange;

	public static void Create(Action onExec)
	{
		GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("UI/layoutParts/TransitionToTwo/TransitionDialog")) as GameObject;
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		SystemText systemText = Data.SystemText;
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		dialogBase.SetButtonText(systemText.Get("BeyondHandover_0003"), systemText.Get("Common_0005"));
		dialogBase.SetTitleLabel(systemText.Get("BeyondHandover_0001"));
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetObj(gameObject);
		TransitionDialog transitionDialog = gameObject.GetComponent<TransitionDialog>();
		transitionDialog.Initialize(onExec);
		dialogBase.SetButtonDelegate(new EventDelegate(delegate
		{
			transitionDialog.PublishCode();
		}));
		dialogBase.SetButtonDisable(isEnableOK: true);
	}

	private void Initialize(Action onExec)
	{
		_toggle.onChange.Add(new EventDelegate(delegate
		{
			OnChangeToggle();
		}));
		_completePublishTransitionCode = onExec;
		_coutionLabel.text = Data.SystemText.Get("BeyondHandover_0012");
		_coutionTitleLabel.text = Data.SystemText.Get("BeyondHandover_0016");
		_scrollView.GetComponent<FlexibleGrid>().Reposition();
		_scrollView.ResetPosition();
	}

	private void OnChangeToggle()
	{
		if (!_firstToggleCall)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(_toggle.value ? Se.TYPE.SYS_TOGGLE_ON : Se.TYPE.SYS_TOGGLE_OFF);
			OnChange.Call(_toggle.value);
			base.transform.parent.GetComponent<DialogBase>().SetButtonDisable(!_toggle.value);
		}
		_firstToggleCall = false;
	}

	private void PublishCode()
	{
		_completePublishTransitionCode.Call();
	}
}
