using UnityEngine;
using System.Collections;

public class CountdownTimerScript : MonoBehaviour {

	// How many seconds we want the timer to be for
	public int journeyLegLength = 300;

	private float startTime = 0.0f;
	private int remainingSeconds = 0;
	private int remainingSecondsRounded = 0;

	private bool timerExpired = false;

	void Awake() {
		startTime = Time.time;
	}

	void Start(){

		float GUITime = Time.time - startTime;
		
		remainingSeconds = journeyLegLength - (int)GUITime;

	}

	void Update(){

		//DEBUG
		/*
		if(Input.GetKeyUp(KeyCode.Q)){
			remainingSeconds = 0;
		}
		*/
		
		if(remainingSeconds == 0){
			
			//Debug.Log("Time is Expired");
			timerExpired = true;
			
		}else{
			// Adjust time for when script was run (rather than overall program start)
			float GUITime = Time.time - startTime;
			
			remainingSeconds = journeyLegLength - (int)GUITime;
			
			// Round up
			remainingSecondsRounded = Mathf.CeilToInt(remainingSeconds);

		}


		


	}

	public bool isTimerExpired(){
		return timerExpired;
	}

	public int getSecondsRemaining(){
		return remainingSeconds;
	}

	public void resetTimer(){

		startTime = Time.time;
		float GUITime = Time.time - startTime;
		remainingSeconds = journeyLegLength - (int)GUITime;
		timerExpired = false;

	}

}
