using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

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

    private Action onClick = null;

    public void Show(string title, string props = null, Action onClickCallback = null) {
        titleLabel.text = title;
        propsLabel.text = props ?? string.Empty;
        propsLabel.gameObject.SetActive(!string.IsNullOrEmpty(props));
        onClick = onClickCallback;
        button.interactable = onClickCallback != null;
    }

    private void OnClick()
    {
        onClick?.Invoke();
    }

    public void Start()
    {
        button.onClick.AddListener(OnClick);
    }

    private void OnDestroy()
    {
        button.onClick.RemoveListener(OnClick);
    }
}
