using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public sealed class BuildButton : MonoBehaviour
{
    [SerializeField]
    private Button button = null;
    [SerializeField]
    private Text titleLabel = null;

    public void Show(string title, int cost, UnityAction onClick)
    {
        gameObject.SetActive(true);
        button.onClick.RemoveAllListeners();
        button.onClick.AddListener(onClick);
        titleLabel.text = $"{title} ({cost})";
    }

    public void Hide()
    {
        button.onClick.RemoveAllListeners();
        gameObject.SetActive(false);
    }

    private void OnDestroy()
    {
        button.onClick.RemoveAllListeners();
    }
}
