using UnityEngine;
using UnityEngine.UI;

public class InGameGUIController : MonoBehaviour {

    public Text collectedApples;
    public Text sessionDoneMessage;
    public Button buttonMainMenu;

    public void Start() {
        ToggleSessionOverVisibility(false);
    }

    public void ToggleSessionOverVisibility(bool visible) {
        sessionDoneMessage.gameObject.SetActive(visible);
        buttonMainMenu.gameObject.SetActive(visible);
    }

    public void OpenMainMenu() {
        Application.LoadLevel("AStartmenu");
    }

    public void AppleCollected() {
        UpdateCollectedApples();
    }

    private void UpdateCollectedApples() {
        string text
          = Localizer.Instance.GetText("InGameGUI.CollectedApples",
                GameStateManager.Instance.CollectedApplesCount,
                GameStateManager.Instance.AllApplesCount);
        collectedApples.text = text;
    }

    public void GameStateChanged() {
        switch (GameStateManager.Instance.CurrentGameState) {
            case GameState.Playing:
                UpdateCollectedApples();
                break;
            case GameState.PlayerCrashed:
                sessionDoneMessage.text
                  = Localizer.Instance.GetText("InGameGUI.GameOver");
                ToggleSessionOverVisibility(true);
                break;
            case GameState.AllApplesCollected:
                sessionDoneMessage.text
                  = Localizer.Instance.GetText("InGameGUI.ApplesDone");
                ToggleSessionOverVisibility(true);
                break;
        }
    }
}
