using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

[RequireComponent(typeof(OutlineFx.OutlineFx))]
public class MyButton : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField]
    private UnityEvent _onClick;

    
    // references
    private OutlineFx.OutlineFx _outlineFx;
    
    private void Awake()
    {
        if (!TryGetComponent(out Collider2D _))
        {
            Debug.LogError("MyButton needs a Collider2D to work", gameObject);
        }
        
        _outlineFx = GetComponent<OutlineFx.OutlineFx>();
        _outlineFx.enabled = false;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        _onClick.Invoke();
    }
    public void OnPointerEnter(PointerEventData eventData)
    {
        _outlineFx.enabled = true;
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        _outlineFx.enabled = false;
    }
}
