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

public class Shit : MonoBehaviour {

	public Boy boy;
	static public int day = 1;
	public Image image_fade;
	public Text text_day;
	public string nextScene;

	static public int points;

	//check stuff
	public static bool ate;
	public static int dayNotEats;
	public static bool dressed;
	public static bool toilet;
	public static int daysNasty;
	public static bool shower;
	public static bool feedPet;
	public static int daysStarvePet;
	public static bool cleanUp;
	public static int DaysNotClean;

	bool end = false;
	List<GameObject> things = new List<GameObject>();

	Timer wait;

	void Start () {
		wait = new Timer(2);
		text_day.text = "Day " + day;
		newDay();
	}

	void newDay() {

		dayNotEats = (ate) ? 0 : dayNotEats + 1;
		daysNasty = (shower) ? 0 : daysNasty + 1;
		DaysNotClean = (cleanUp) ? 0 : DaysNotClean + 1;
		daysStarvePet = (feedPet) ? 0 : daysStarvePet + 1;

		if (dayNotEats > 0) {
			boy.GetComponent<UnityStandardAssets.Characters.FirstPerson.RigidbodyFirstPersonController>().movementSettings.ForwardSpeed -= dayNotEats;
			boy.dep = true;
		}
		else {
			boy.dep = false;
		}

		if (daysNasty > 0) {

		}
		else {
			//go back to normal
		}

		if (DaysNotClean > 0) {

		}
		else {

		}

		if (daysStarvePet > 0) {

		}
		else {

		}

		ate = false;
		dressed = false;
		toilet = false;
		shower = false;
		feedPet = false;
		cleanUp = false;
	}
	
	// Update is called once per frame
	void Update () {
		if (wait.Check() && !end) {
			FadeOut();
		}
		else if(end){
			FadeIn();
		}
	}

	public void EndDay() {
		end = true;
		day++;
	}

	void FadeOut() {
		Color temp = image_fade.color;
		temp.a = Mathf.Lerp(image_fade.color.a, 0, Time.deltaTime * 1);
		image_fade.color = temp;
		Color tTemp = text_day.color;
		temp.a = Mathf.Lerp(text_day.color.a, 0, Time.deltaTime * 1);
		text_day.color = temp;
	}

	public void FadeIn() {
		Color temp = image_fade.color;
		temp.a = Mathf.Lerp(image_fade.color.a, 1.0f, Time.deltaTime * 1);
		image_fade.color = temp;
		if (image_fade.color.a > .9f) {
			LoadScene(nextScene);
		}
	}

	public void LoadScene(string s) {
		SceneManager.LoadScene("Day1");
	}
}
