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


public class StartingMenuManager : MonoBehaviour{

    private string initialWorld = "world";
    private string menu = "startingMenuScene";
    private bool moveL = false;
    private bool moveR = false;
    private GameObject loadMenu;
    private GameObject settingsMenu;
    private GameObject mainMenu;

    void Awake() {
        this.loadMenu = GameObject.Find("LoadedGames");
        this.settingsMenu = GameObject.Find("Settings");
        this.mainMenu= GameObject.Find("Buttons");

        this.loadMenu.SetActive(false);
        this.settingsMenu.SetActive(false);
        this.mainMenu.SetActive(true);
    }
 
    public void MainMenuStart(int i) {


        if (i == -1)
        {
            LoadSavePlayerStats.isLoaded = false;
            LoadSavePlayerStats.tmp = null;
            Application.LoadLevel(initialWorld);

        }

        else
        {
            LoadSavePlayerStats.isLoaded = true;
            Debug.Log("LOADING SLOT " + i);
            LoadSavePlayerStats.tmp = LoadSavePlayerStats.Load(i);
            Application.LoadLevel(LoadSavePlayerStats.tmp.scene);

        }


        
    }

    public void MainMenuLoadGame() {
        Debug.Log("Load game");

        this.mainMenu.SetActive(false);
        this.loadMenu.SetActive(true);
//        LoadSavePlayerStats.Load();
        LoadSavePlayerStats.Load();

        for (int i = 0; i < LoadSavePlayerStats.savedGames.Length; i++)
        {
            PlayerStats p = LoadSavePlayerStats.savedGames[i];
            if (p == null)
            {
                GameObject b = (GameObject.Find("SaveData" + (i + 1)));
                b.GetComponent<Button>().interactable = false;
                b.transform.Find("Text").GetComponent<Text>().text = "No saved data";
            }
        }


        moveL = true;
    }   

    public void MainMenuSettings() {
        Debug.Log("Settings");
        this.mainMenu.SetActive(false);
        this.settingsMenu.SetActive(true);
        moveL = true;
    }

    public void MainMenuQuit() {
        Debug.Log("Quit");
        Application.Quit();
    }

    public void GoBack()
    {
        this.loadMenu.SetActive(false);
        this.settingsMenu.SetActive(false);
        this.mainMenu.SetActive(true);
    }

    public void RemoveData()
    {
        LoadSavePlayerStats.RemoveData();
    }

}
