using System;
using System.Text.RegularExpressions;
using Cute;
using UnityEngine;

public class NtDataTranslateInput : MonoBehaviour
{
	public UIInput InputEmail1;

	public UIInput InputEmail2;

	public UILabel TxtEmailTitle1;

	public UILabel TxtEmailTitle2;

	public UILabel TxtEmailTip;

	public string EmailAddress;

	private NtDataTranslateInfo info;

	private void Start()
	{
		initUI();
		initEventListener();
	}

	private void initUI()
	{
		info = NtDataTranslateManager.GetInstance().TranslateInfo;
		TxtEmailTitle1.text = info.emailAddress1;
		TxtEmailTitle2.text = info.emailAddress2;
		TxtEmailTip.text = string.Empty;
	}

	private void initEventListener()
	{
		EventDelegate.Add(InputEmail1.onChange, onValueChange);
		EventDelegate.Add(InputEmail2.onChange, onValueChange);
	}

	private void onValueChange()
	{
		if (checkInput().Equals(info.emailAddressTip1))
		{
			if (!string.IsNullOrEmpty(InputEmail2.value))
			{
				TxtEmailTip.text = checkInput();
			}
			else
			{
				TxtEmailTip.text = "";
			}
		}
		else
		{
			TxtEmailTip.text = checkInput();
		}
	}

	private string checkInput()
	{
		string result = string.Empty;
		string value = InputEmail1.value;
		string value2 = InputEmail2.value;
		if (string.IsNullOrEmpty(value))
		{
			result = info.emailAddressTip2;
		}
		else if (!Regex.IsMatch(value, "(?i)^([a-z0-9\\+_\\-]+)(\\.[a-z0-9\\+_\\-]+)*@([a-z0-9\\-]+\\.)+[a-z]{2,6}$"))
		{
			result = info.emailAddressTip2;
		}
		else if (!value2.Equals(value))
		{
			result = info.emailAddressTip1;
		}
		return result;
	}

	public void UpLoadEmail(Action callback)
	{
		string text = checkInput();
		if (string.IsNullOrEmpty(text))
		{
			EmailAddress = InputEmail1.value;
			callback.Call();
			return;
		}
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetTitleLabel(info.ERROR_TITLE);
		dialogBase.SetText(text);
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.DecisionBtn);
		dialogBase.SetPanelDepth(6000);
	}
}
