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

public class UIManager : MonoBehaviour {
    public Dropdown drpdwnProfiles;

    List<string> profilesName;
    public static string name;
    public GameObject pnlMain;
    public GameObject pnlSetting;
    public AudioSource audioS;
    public Slider audioController;
    public GameObject pnlHelp;
    public GameObject currentPanel;
    public GameObject pnlAddNewGame;
    public GameObject selectPanel;
    public InputField nameinf;
    public ToggleGroup toggleGroup;
    public Text gameButtonLabel;
    Toggle myToggles;
    void Start()
    {
        print(Application.persistentDataPath +
 "/GameData.gd");
        currentPanel = pnlMain;
    }
    public void OnExitBtnClicked()
    {
        print("Application Quit");
        Application.Quit(); 
    }
    public void OnSettingBtnClicked()
    {
        currentPanel = pnlSetting;
        pnlMain.SetActive(false);
        currentPanel.SetActive(true);
    }
    public void OnBackBtnClicked()
    {
        currentPanel.SetActive(false);
        pnlMain.SetActive(true);
        currentPanel = pnlMain;
    }

    public void OnValueChanged()
    {
        audioS.volume = audioController.value;
    }
    public void OnHelpbtnClicked()
    {
        currentPanel = pnlHelp;
        pnlMain.SetActive(false);
        currentPanel.SetActive(true);
    }
    public void OnAddNewGameClicked()
    {
        currentPanel.SetActive(false);
        currentPanel = pnlAddNewGame;
        currentPanel.SetActive(true);
    }
    public void OnSelectGameClicked()
    {
        currentPanel.SetActive(false);
        currentPanel = selectPanel;
        currentPanel.SetActive(true);
        //gameButtonLabel.text = PlayerPrefs.GetString("ProfileName") + "     " + PlayerPrefs.GetString("Hardness");
        SaveLoad.Load();
        List<string> profilesName = new List<string>();
        foreach (var item in SaveLoad.myGames)
        {
            profilesName.Add(item.profileName+" "+item.score);
        }
        drpdwnProfiles.AddOptions(profilesName);
    }
    public void OnCreateGameBtnClicked()
    {
        /* name = nameinf.text;
         PlayerPrefs.SetString("ProfileName", nameinf.text);
         foreach (var item in toggleGroup.ActiveToggles())
         {
             PlayerPrefs.SetString("Hardness",item.name);
         }
         */
        Game tempGame = new Game();
        tempGame.profileName = nameinf.text;
        foreach (var item in toggleGroup.ActiveToggles())
        {
            tempGame.hardness=item.name;
        }
        tempGame.level = 1;
        tempGame.score = 0;
        Game.currentGame = tempGame;
		SaveLoad.Save(true);

        Application.LoadLevel(1);
    }
    public void OnDrpDwnValueChanged()
    {
        int index;
        index = drpdwnProfiles.value;
        Game.currentGame= SaveLoad.myGames[index];
        Application.LoadLevel(Game.currentGame.level);
    }


   
}
