using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Assets.Scripts.Managers;

public class NightTimer : MonoBehaviour {

	#region variables
	private float _startValue = 10f;
	private float _currentValue;

	private Slider _slider;
	#endregion


	#region getters and setters
	public float Normalized {
		get {
			float v = (_currentValue / _startValue);
			if (v > 1) v = 1;
			if (v < 0) v = 0;

			return v;
		}
	}
	#endregion


	#region events
	void Start () {

		_slider = GetComponent <Slider> ();
		Reset ();
		
	}

	void Update () {

		if (PlayerMovement.ControlsEnabled) {
			if (GameManager.CurrentGameTime == GameTime.Night) {
				_currentValue -= Time.deltaTime;
				
				if (this.Normalized == 0) {
					_currentValue = _startValue;
					DayNightManager.SetDay ();
				}
			} else {
				if (_currentValue < _startValue) {
					_currentValue += Time.deltaTime;
				} else if (_currentValue > _startValue) {
					_currentValue = _startValue;
				}
			}
		}
		_slider.value = this.Normalized;
		
	}
	#endregion


	#region methods
	public void Reset () {

		_currentValue = _startValue;
		
	}
	#endregion
	
}
