using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class UIBuildingButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField] private Button button;
    [SerializeField] private Image image;
    [SerializeField] private TextMeshProUGUI text;
    [SerializeField] private AudioClipGroup clickSound;
    private BuildingData buildingData;

    public void Initiate(BuildingData buildingData)
    {
        this.buildingData = buildingData;
        button.onClick.AddListener(() =>
        {
            clickSound.Play();
            Events.BuildingSelected(buildingData);
        });
        image.sprite = buildingData.BuildingPrefab.GetComponent<SpriteRenderer>().sprite;
        text.text = buildingData.Name;
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        Events.ShowTooltip(buildingData, transform.position);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        Events.HideTooltip();
    }
}
