using System;
using UnityEngine;
using UnityEngine.UI;

public class ChestRewardSelection : MonoBehaviour
{
    public static event Action DiamondAndLifeSelected;
    public static event Action TorchAbilitySelected;
    public static event Action BlackDiceAbilitySelected;
    
    [SerializeField] private Button diamondAndLifeButton;
    [SerializeField] private Button torchButton;
    [SerializeField] private Button blackDiceButton;
    
    private void OnEnable()
    {
        RoomReward.ChestRewarded += HandChestRewarded;
        diamondAndLifeButton.onClick.AddListener(HandleDiamondAndLifeSelected);
        torchButton.onClick.AddListener(HandleTorchSelected);
        blackDiceButton.onClick.AddListener(HandleBlackDiceSelected);
    }

    private void HandChestRewarded()
    {
        gameObject.SetActive(true);
    }

    private void HandleDiamondAndLifeSelected()
    {
        diamondAndLifeButton.interactable = false;
        DiamondAndLifeSelected?.Invoke();
        gameObject.SetActive(false);
    }

    private void HandleTorchSelected()
    {
        torchButton.interactable = false;
        TorchAbilitySelected?.Invoke();
        gameObject.SetActive(false);
    }

    private void HandleBlackDiceSelected()
    {
        blackDiceButton.interactable = false;
        BlackDiceAbilitySelected?.Invoke();
        gameObject.SetActive(false);
    }
}
