using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MenuManager : MonoBehaviour
{
    public Text txtUsername;
    public Text txtMoney;

    public Button playBtn;
    public Button leaderboardBtn;
    public Leaderboard leaderboard;
    // public Store store;
    public static MenuManager instance;
    void Start()
    {
        instance = this;
        if(!DataManager.LoggedIn){SceneManager.LoadScene(0); return;}
        Refresh();

        playBtn.onClick.AddListener(OnPlay);  
        leaderboardBtn.onClick.AddListener(OnLeaderboardBtn);
    }

    void OnPlay(){
        SceneManager.LoadScene(2);
    }

    void OnLeaderboardBtn(){
        leaderboard.Show();
    }

    public static void Refresh(){
        if(instance != null){
            instance.refresh();
        }
    }

    void refresh(){
        
        txtUsername.text = txtUsername.text.Replace("{username}", DataManager.Username);
        txtMoney.text = "Personal Best: $" + DataManager.best.ToString();  
    }
}
