using DG.Tweening;
using DG.Tweening.Core;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class BalloonNotification : MonoBehaviour
{
	public static BalloonNotification Show(string message, Transform target)
	{
		var notificationGO = Instantiate(ApplicationResources.Instance.BalloonNotificationPrefab) as GameObject;
		notificationGO.transform.SetParent(target);
		notificationGO.transform.localPosition = new Vector3(0f, 3f, 0f);

		var notification = notificationGO.GetComponent<BalloonNotification>();
		notification.Show(message);
		return notification;
	}

	public Text Text;
	//public CanvasRenderer TextCanvasRenderer;
	public CanvasGroup CanvasGroup;

	public void Show(string message)
	{
		Text.text = message;
		//TextCanvasRenderer.SetAlpha(0f);
		CanvasGroup.alpha = 0f;

		//Text.CrossFadeAlpha(1f, 0.4f, true);
		CanvasGroup.DOFade(1f, 0.4f);

		CancelInvoke("FadeOut");
		Invoke("FadeOut", 1.3f);
	}

	public void FadeOut()
	{
		CancelInvoke("FadeOut");

		//Text.CrossFadeAlpha(0f, 0.4f, true);
		CanvasGroup.DOFade(0f, 0.4f);
	}
}
