using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class DirectionContainerScript : MonoBehaviour
{

	public Transform upArrow;
	public Transform directions;



	public void AddDirection (Direction dir)
	{
		Transform dirImage;
		switch (dir) {

		case Direction.Up:
			dirImage = (Transform)Instantiate (upArrow, Vector3.zero, Quaternion.Euler (0, 0, 0));
			break;

		case Direction.Right:
			dirImage = (Transform)Instantiate (upArrow, Vector3.zero, Quaternion.Euler (0, 0, 270));
			break;

		case Direction.Down:
			dirImage = (Transform)Instantiate (upArrow, Vector3.zero, Quaternion.Euler (0, 0, 180));
			break;
		
		case Direction.Left:
			dirImage = (Transform)Instantiate (upArrow, Vector3.zero, Quaternion.Euler (0, 0, 90));
			break;

		default:
			dirImage = (Transform)Instantiate (upArrow, Vector3.zero, Quaternion.Euler (0, 0, 0));
			break;
		}

		dirImage.SetParent (directions);

		Vector3 pos = new Vector3((directions.childCount-1)*0.5f,0,0);

		transform.localPosition = -pos + Vector3.back + Vector3.up;
		dirImage.localPosition = pos;
		directions.localPosition = pos*0.5f;
	}

	public void RemoveDirection(int firstMatch, int enemyPatternSize){
		for (int i = 0; i < enemyPatternSize; i++) {
			DestroyImmediate(directions.GetChild (firstMatch).gameObject);
		}

		Vector3 pos = new Vector3((directions.childCount-1)*0.5f,0,0);

		transform.localPosition = -pos + Vector3.back + Vector3.up;

		directions.localPosition = pos*0.5f;

		for(int i=0;i<directions.childCount;i++)
			centerDirections (i);

	}

	public void centerDirections(int childIndex){
		directions.GetChild (childIndex).localPosition = new Vector3(childIndex*0.5f,0,0);;

	}
}
