using System.Collections;
using System.Collections.Generic;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class MenuManager : MonoBehaviour
{
    public Text highScoreValue;
    public Text CoinsValue;
    public Text SoundButtonText;


    public Text magnetLevelText;
    public Text magnetButtonText;

    public Text immortalityLevelText;
    public Text immortalityButtonText;


    public Powerup magnet;
    public Powerup immortality;

    public GameObject mainMenuPanel;
    public GameObject upgradeStorePanel;

    public int hs = 0;
    public int coins = 0;

    void Start()
    {
        Screen.SetResolution(1600, 1000, false);

        if (PlayerPrefs.HasKey("HighScoreValue"))
        {
            hs = PlayerPrefs.GetInt("HighScoreValue");
        }
        if (PlayerPrefs.HasKey("Coins"))
        {
            coins = PlayerPrefs.GetInt("Coins");
        }

        UpdateUI();
    }

    void Update()
    {
    }

    public void UpdateUI()
    {
        highScoreValue.text = $"SCORE: {hs}";
        CoinsValue.text = $"COINS: {coins}";

        if (SoundManager.instance.GetMuted())
        {
            SoundButtonText.text = "TURN ON SOUND";
        }
        else
        {
            SoundButtonText.text = "TURN OFF SOUND";
        }

        immortalityLevelText.text = immortality.ToString();
        immortalityButtonText.text = immortality.UpgradeCostString();
        magnetLevelText.text = magnet.ToString();
        magnetButtonText.text = magnet.UpgradeCostString();
    }

    public void PlayButton()
    {
        SceneManager.LoadScene("Game");
    }
    public void SoundButton()
    {
        SoundManager.instance.ToogleMuted();

        UpdateUI();
    }
    public void OpenUpgradeStore()
    {
        mainMenuPanel.SetActive(false);
        upgradeStorePanel.SetActive(true);
    }
    public void CloseUpgradeStore()
    {
        mainMenuPanel.SetActive(true);
        upgradeStorePanel.SetActive(false);
    }
}
