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

public class StatButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
    [SerializeField] StatSO statData;
    [SerializeField] Image backgroundImage;
    [SerializeField] Image statImage;

    private PointerEventData eventData;

    private void Start()
    {
        if (statData.ButtonAction == ButtonAction.press)
            GetComponent<Button>().onClick.AddListener(ButtonClick);

        backgroundImage.color = statData.StatColor;
        statImage.sprite = statData.StatImage;
    }

    private void ButtonClick()
    {
        statData.Action.InvokeAction();
    }

    private void ButtonHold()
    {
        statData.Action.InvokeAction();
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        EventManager.Instance.onTick += ButtonHold;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        Debug.Log("pointerup");
        EventManager.Instance.onTick -= ButtonHold;
    }
}
