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

public class NavigationManager : MonoBehaviour
{
	private float timelastactive;
	private GameObject navMenu;

	public void Start()
	{
		//navMenu = GameObject.Find("Navigation Menu");
		navMenu = gameObject.transform.Find("Navigation Menu").gameObject;
	}

	public void Update()
	{
		if (Input.GetKeyDown (KeyCode.Escape))
		{
			if (navMenu.activeSelf) {
				CloseNavMenu ();
				timelastactive = Time.time;
			}
			else if (Time.time > (timelastactive + 1.0f))
			{
				PreviousPage ();
			}
		}
	}

	public bool isActive()
	{
		return navMenu.activeSelf;
	}

	public void OpenNavMenu()
	{
		navMenu.SetActive (true);
	}

	public void CloseNavMenu()
	{
		navMenu.SetActive (false);
	}

	public void LoadScene(string scene)
	{
		string scenetext = scene;
		Debug.Log (" " + scenetext);

		switch (scenetext) {
		case "Start":
			if (!(SceneManager.GetActiveScene ().name == "Home"))
				SceneManager.LoadScene ("Home");
			break;
		case "Run":
			if (!(SceneManager.GetActiveScene ().name == "Goals"))
				SceneManager.LoadScene ("Goals");
			break;
		case "Profile":
			if (!(SceneManager.GetActiveScene ().name == "Stats"))
				SceneManager.LoadScene ("Stats");
			break;
		case "Monster Creator":
			if (!(SceneManager.GetActiveScene ().name == "MonsterCreator"))
				SceneManager.LoadScene ("MonsterCreator");
			break;
		default:
			if (!(SceneManager.GetActiveScene ().name == scenetext))
				SceneManager.LoadScene (scenetext);
			break;
		}
	}

	public void PreviousPage()
	{
		string currentscene = SceneManager.GetActiveScene ().name;

		switch(currentscene) {
		case "Main":
		case "Home":
			Application.Quit();
			break;
		case "MonsterCreator":
			SceneManager.LoadScene ("Stats");
			break;
		case "Leaderboard":
			SceneManager.LoadScene ("Stats");
			break;
		case "Goals":
		case "Credits":
		case "Stats":
		default:
			SceneManager.LoadScene ("Home");
			break;
		}
	}
}
