using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class ChatSendTextUI : MonoBehaviour
{
	[SerializeField]
	private UIButton _buttonStartInput;

	[SerializeField]
	private ChatOpenCloseAnimation _uiOpenCloseAnimation;

	[SerializeField]
	private UIButton _buttonSendMessage;

	[SerializeField]
	private UIInputWizard _uiInputPC;

	[SerializeField]
	private UIInputWizard _uiInputMobile;

	private UIInputWizard _uiInput;

	private Action<ChatOpenCloseAnimation> _onCloseInputUI;

	public bool IsOpen => _uiOpenCloseAnimation.IsOpen;

	public void Init(Action<string> onSendTextMessage, Action<ChatOpenCloseAnimation> onOpenInputUI, Action<ChatOpenCloseAnimation> onCloseStampListUI)
	{
		_uiInput = _uiInputPC;
		_uiInputMobile.gameObject.SetActive(value: false);
		_uiOpenCloseAnimation.Init(isOpenedDefault: false);
		_onCloseInputUI = onCloseStampListUI;
		_buttonStartInput.onClick.Clear();
		_buttonStartInput.onClick.Add(new EventDelegate(delegate
		{
			_uiOpenCloseAnimation.ToggleStateAndStartAnimation();
			if (_uiOpenCloseAnimation.IsOpen)
			{
				UICamera.selectedObject = _uiInput.gameObject;
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_ON);
				onOpenInputUI.Call(_uiOpenCloseAnimation);
			}
			else
			{
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_TOGGLE_OFF);
				_onCloseInputUI.Call(_uiOpenCloseAnimation);
			}
		}));
		_uiInput.onSubmit.Clear();
		_uiInput.onSubmit.Add(new EventDelegate(delegate
		{
			_uiInput.value = _uiInput.value.Replace("\n", "");
		}));
		_uiInput.onDeselect.Clear();
		_uiInput.onDeselect.Add(new EventDelegate(delegate
		{
			_uiInput.value = _uiInput.value.Replace("\n", "");
		}));
		_buttonSendMessage.onClick.Clear();
		_buttonSendMessage.onClick.Add(new EventDelegate(delegate
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
			if (!(_uiInput.value == string.Empty))
			{
				onSendTextMessage.Call(_uiInput.value);
			}
		}));
	}

	public void CloseInputUI(bool isClearText, Action onAnimationEndCallBack = null)
	{
		if (IsOpen)
		{
			if (isClearText)
			{
				_uiInput.value = string.Empty;
			}
			_uiOpenCloseAnimation.StartCloseAnimation(onAnimationEndCallBack);
			_onCloseInputUI.Call(_uiOpenCloseAnimation);
		}
	}
}
