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

public class GameUI : MonoBehaviour {

	[SerializeField]Text _displayTime;

	[SerializeField]CharacterProfile profilePrefab;

	[SerializeField]Transform characterProfileContainer;

	List<CharacterProfile> _profiles;

	Vector3 _playerLeftStarting = new Vector3(-311.6f, -35.0f, 0.0f);
	Vector3 _playerRightStarting = new Vector3(311.63f, -35.0f, 0.0f);
	[SerializeField]Vector3 _profileDestination;

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void UpdateTime(float newValue)
	{
		this._displayTime.text = ((int)newValue).ToString();

		this._displayTime.color = newValue > 5 ? Color.white : Color.red;
	}

	public void ClearRightProfiles()
	{
		if (this._profiles != null)
		{
			for(int i = this._profiles.Count-1; i >= 1; i--)
			{
				Destroy(this._profiles[i].gameObject);
				this._profiles.RemoveAt(i);
			}
		}
	}

	public void ResetProfiles()
	{
		if (this._profiles != null)
		{
			for(int i = this._profiles.Count-1; i >= 0; i--)
			{
				Destroy(this._profiles[i].gameObject);
			}
		}

		this._profiles = new List<CharacterProfile>();
	}

	public void ClearTime()
	{
		this._displayTime.text = "";
	}

	public CharacterProfile CreateProfile()
	{
		CharacterProfile newProfile = Instantiate(this.profilePrefab, this.characterProfileContainer);

		if (this._profiles.Count > 0)
		{
			newProfile.transform.localPosition = this._playerRightStarting + (new Vector3((this._profiles.Count - 1) * -130, 0, 0));
		}
		else
		{
			newProfile.transform.localPosition = this._playerLeftStarting;
		}

		this._profiles.Add(newProfile);

		return newProfile;
	}
}
