﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine.Analytics;




public class MenuNavigationController : MonoBehaviour {
    
    public GameObject mainPanel, playPanel, creditsPanel, optionsPanel, customizePanel, statsPanel, leaderboardPanel, loginPanel, signupPanel, loadingPanel;


    void Awake() {
		Cursor.visible = true;
		Cursor.lockState = CursorLockMode.None;
        if(PlayFabClientAPI.IsClientLoggedIn()) {
            GoToTeacherMainMenu();
        }
    }

	void Update () {
		if (SceneManager.GetActiveScene ().name == "Tutorial Island") {
			if (Input.GetKeyDown (KeyCode.G)) {
				SceneManager.LoadScene (0);
			}
		}
	}
    
    public void PlayButton() {
        SetActivePanel(playPanel);
    }

    public void CreditsButton() {
        SetActivePanel(creditsPanel);
    }

    public void OptionsButton() {
        SetActivePanel(optionsPanel);
    }

	public void CustomizeButton() {
		SetActivePanel(customizePanel);
	}

    public void CreateAccountButton() {
        SetActivePanel(signupPanel);
    }

    public void StatsButton() {
        SetActivePanel(statsPanel);
    }

    public void LoginToMenu() {
        SetActivePanel(mainPanel);
    }

    public void LeaderboardButton() {
        SetActivePanel(leaderboardPanel);
    }

    public void BackToLogin() {
        SetActivePanel(loginPanel);
    }

    // bring you back to root main menu
    public void BackButton() {
        SetActivePanel(mainPanel);
    }

	public void PlayTutorial()
    {
        SceneManager.LoadScene(2);
	}

    void SetActivePanel(GameObject panel) {
        if(mainPanel) mainPanel.SetActive(panel == mainPanel);
        if(playPanel) playPanel.SetActive(panel == playPanel);
        if(creditsPanel) creditsPanel.SetActive(panel == creditsPanel);
        if(optionsPanel) optionsPanel.SetActive(panel == optionsPanel);
        if(statsPanel) statsPanel.SetActive(panel == statsPanel);
		if(customizePanel) customizePanel.SetActive(panel == customizePanel);
		if(loginPanel) loginPanel.SetActive(panel == loginPanel);
		if(signupPanel) signupPanel.SetActive(panel == signupPanel);
		if(leaderboardPanel) leaderboardPanel.SetActive(panel == leaderboardPanel);
        if(loadingPanel) loadingPanel.SetActive(panel == loadingPanel);
    }

    public void GoToTeacherMainMenu() {
		SetActivePanel (mainPanel);
    }
}
