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

public class GameUI : MonoBehaviour {

    public GameManager gm;
    public PlayerController pc;
    private int maxTimeSteps = 20;
	private int timeStep = 0;

	// Use this for initialization
	void Start()
	{
		MaxTimeSteps = gm.numberOfTurns;

	}

	// Update is called once per frame
	void Update()
	{

	}

	public int MaxTimeSteps
    {
        get { return maxTimeSteps; }
        set
		{
			maxTimeSteps = value;
			UpdateTimeLabel();
		}
    } 

    public int TimeStep
    {
        get { return timeStep; }
        set
        {
			if (value >= 0 && value < maxTimeSteps)
			{
				var forward = timeStep < value;
				var change = timeStep != value;
				if (change)
				{
					timeStep = value;
					IncrementClock(forward);
				}
			}
		}
	}

	public void StepForward()
	{
		TimeStep++;
	}

	public void StepBack()
	{
		TimeStep--;
	}

	private void IncrementClock(bool forward)
	{
		var clockHand = GameObject.Find("ClockHand");
		clockHand.GetComponent<RectTransform>().Rotate(new Vector3(0, 0, 360 / 12 * (forward ? -1 : 1)));

		UpdateTimeLabel();

        if(!forward)
        {
            pc.RevertCharacter();
        }
	}

	private void UpdateTimeLabel()
	{
		var timeLabel = GameObject.Find("TimeLabel");
		Text text = timeLabel.GetComponent<Text>();
		text.text = string.Format("{0}/{1}", TimeStep + 1, MaxTimeSteps);
	}


    public void OnClickNeedle()
    {
        gm.GoToEnd();
    }
    // Vaccine button clicked
    // Player.Vaccinate(Npc that is selected);

    // Flag button clicked
    // if (Player.Flag(Npc that is selected))
    // {
    //      Display flag icon above NPC.
    // }
    // else
    // {
    //      Confirm with user that they want to move the flag from one Npc to another.
    //      if (Response = yes)
    //      {
    //          previously-selected-Npc.Flag = false;
    //          newly-selected-Npc.Flag = true;
    //      }
    //      Don't need to do anything special if the player selects "no".
    // }
}
