using UnityEngine;
using UnityEngine.UI;

public sealed class YardUIFoldPanel : MonoBehaviour
{
    [SerializeField]
    private Text stantionName = null;
    [SerializeField]
    private Button backButton = null;
    [SerializeField]
    private Profile profile = null;
    [SerializeField]
    private CreditsUICounter creditsCounter = null;
    [SerializeField]
    private SpaceUICounter spaceCounter = null;
    public Player Player => profile.Player;
    public StarShip StarShip => profile.Player.StarShip;

    public void Show(SpaceStantion stantion)
    {
        gameObject.SetActive(true);
        creditsCounter.Show(Player.Credits);
        spaceCounter.Show(StarShip.GetCargoSpace(), StarShip.GetFullSpace());
        stantionName.text = stantion.Name;
    }

    public void Hide() => gameObject.SetActive(false);

    public void Start()
    {
        backButton.onClick.AddListener(Hide);
    }

    private void OnDestroy()
    {
        backButton.onClick.AddListener(Hide);
    }

    public void Update()
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            Hide();
        }
    }
}
