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

namespace Utils.UI {
	public class UIBarSegment : UISegment {

	  public enum BarOrientation
	  {
		HORIZONTAL,
		VERTICAL
	  
	  }

	  public BarOrientation Orientation;
	  /// <summary>
	  /// Spawns a segment.
	  /// </summary>
	  /// <param name="prefab">Prefab.</param>
	  /// <param name="yRotation">Y rotation.</param>
	  public override void SpawnSegment(GameObject prefab,int segmentIndex) {
		GameObject segment = Instantiate (prefab, Container.transform.position, prefab.transform.rotation) as GameObject;
		segment.transform.SetParent (Container, true);
		segment.transform.localScale = Vector3.one;
		Vector2 p = segment.GetComponent<RectTransform> ().anchoredPosition;
		Image img = segment.GetComponent<Image> ();
		float maxLength = 0;
		switch (Orientation) {
		case BarOrientation.HORIZONTAL:
		  img.fillMethod = Image.FillMethod.Horizontal;
		  	maxLength = GetComponent<RectTransform> ().sizeDelta.x;
		  		p.x = (partL+(2*Padding)) * maxLength*segmentIndex;	
			break;
			case BarOrientation.VERTICAL:
		  	  img.fillMethod = Image.FillMethod.Vertical;
			  maxLength = GetComponent<RectTransform> ().sizeDelta.y;
		  		p.y = (partL+(2*Padding)) * maxLength*segmentIndex;
			break;
		}

		ApplyColor (segment, segmentIndex);

		segment.GetComponent<RectTransform> ().anchoredPosition = p;

		//segment.GetComponent<RectTransform>().rotation = Quaternion.Euler (0, 0, segmentIndex * (partL+(2*Padding))*360);

		//segment.GetComponent<RectTransform>().anchoredPosition

		img.fillAmount = partL;
		Segments.Add (img);
		OriginalPositions.Add (img.rectTransform.localPosition);
	  }



	}
}
