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

public class ScoreManager : MonoBehaviour {

	public string player;

	public Text playTimeText;
	public Text dateText;
	public int successess;
	public Text successesText;
	public Text finalScoreText;

	public Text enterNameText;
	public InputField nameInputField;

	public int lastCheckpoint;

	// Use this for initialization
	void Start ()
	{
		string date = System.DateTime.Today.ToString ();
		dateText.text = date.Substring (0, date.Length - 8);
		successess = 0;
		lastCheckpoint = 0;
	}
	
	// Update is called once per frame
	void Update ()
	{
		//	playTimeText.text = Time.time.ToString("F2");
		string time = System.DateTime.Now.ToString();
		playTimeText.text = time.Substring (time.Length - 8);

		if(successess < 10)
			successesText.text = "0" + successess.ToString();

		else if(successess >= 10)
			successesText.text = successess.ToString();
	

		if (successess > lastCheckpoint + 10)
		{
			Invoke ("DecreaseDisruptInterval", 0);
		}
	
	}


	void DecreaseDisruptInterval()
	{
		Harmonizer[] harmonizers = FindObjectsOfType<Harmonizer> ();

		foreach (var item in harmonizers)
		{
			if (successess > 50)
				item.minInterval = 1f;

			if (item.maxInterval > item.minInterval)
			{
				item.maxInterval -= 1f;
				item.maxInterval = Mathf.Clamp (item.maxInterval, item.minInterval, 30f);
			}
		}

		lastCheckpoint = successess;

		Debug.Log ("Decreased intervals!   Last checkpoint was: " + lastCheckpoint);
	}



	public void ShowFinalScore()
	{
		finalScoreText.text = successess.ToString ()  + "\n" + FindObjectOfType<Reactor>().timeOfDeath;
		finalScoreText.gameObject.SetActive (true);
	}
}