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

public class LanceTween : MonoBehaviour {

	public static LanceTween instance;

	public GameObject lanceRitualsGroup;
	public GameObject lanceDanceComboGroup;
	public GameObject cronoBar;

	public float timeDuration = 1.5f;
	public float EndPointAxisX = 1500f;
	public Ease fadeInEase = Ease.OutElastic;
	public Ease fadeOutEase = Ease.OutElastic;

	[ContextMenu("InitVars")]
	private void InitVar()
	{
		lanceRitualsGroup = GameObject.Find ("LanceRitualsGroup");
		lanceDanceComboGroup = GameObject.Find ("LanceDanceComboGroup");
	}

	void Awake()
	{
		instance = this;
	}

	// Use this for initialization
	void Start () 
	{
		DOTween.Init();
	}

	public void SwipeOutLanceRituals(bool moveInLanceCombo = true)
	{
		if(lanceRitualsGroup != null)
		{
			lanceRitualsGroup.GetComponent<RectTransform>().DOAnchorPos(new Vector2(EndPointAxisX, 0),timeDuration).SetEase(fadeInEase).OnComplete( 
				() => {
					lanceRitualsGroup.SetActive(false);
					if (moveInLanceCombo) 
						SwipeInLanceCombo();
			});
		}
		else
		{
			Debug.Log ("Attach LanceRitualsGroup in Inspector LanceTween.cs");
		}
	}

	public void SwipeInLanceRituals()
	{
		if(lanceRitualsGroup != null)
		{
			lanceRitualsGroup.SetActive(true);
			lanceRitualsGroup.GetComponent<RectTransform>()
				.DOAnchorPos(new Vector2(0, 0),timeDuration).SetEase(fadeInEase);
		}
		else
		{
			Debug.Log ("Attach LanceRitualsGroup in Inspector LanceTween.cs");
		}
	}

	public void SwipeInLanceCombo()
	{
		if(lanceDanceComboGroup != null)
		{
			lanceDanceComboGroup.SetActive(true);

			//Set it out then lerp inside the game.
			lanceDanceComboGroup.GetComponent<RectTransform>().anchoredPosition = new Vector2(EndPointAxisX,0f);
			lanceDanceComboGroup.GetComponent<RectTransform>().DOAnchorPos(new Vector2(0, 0),timeDuration).SetEase(fadeOutEase).OnComplete(
				() => 
				{
					cronoBar.GetComponent<CronoTimeUpdate>().ShowMe();
				});
		}
		else
		{
			Debug.Log ("Attach lanceDanceComboGroup in Inspector LanceTween.cs");
		}
	}

	public void SwipeOutLanceCombo()
	{
		if(lanceDanceComboGroup != null)
		{
			lanceDanceComboGroup.GetComponent<RectTransform>().DOAnchorPos(new Vector2(EndPointAxisX, 0),timeDuration).SetEase(fadeOutEase).OnComplete(
				() => 
				{
					//cronoBar.GetComponent<CronoBar>().ShowMe();
				});
		}
		else
		{
			Debug.Log ("Attach lanceDanceComboGroup in Inspector LanceTween.cs");
		}
	}

}
