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

namespace Assets.Source.Content.UI.Components
{
    public class ClickHoldHandler : MonoBehaviour, IPointerDownHandler
    {
        public float HoldTriggerDuration = 1f;
        public UnityEvent OnHold;

        private float _holdTime;
        private bool _holding;

        public void OnPointerDown(PointerEventData eventData)
        {
            _holdTime = 0;
            _holding = true;
        }

        void Update()
        {
            if (!_holding)
                return;

            _holdTime += Time.deltaTime;
            if (_holdTime >= HoldTriggerDuration)
                FireHold();
        }

        private void FireHold()
        {
            OnHold.Invoke();
            _holdTime = 0;
            _holding = false;
        }
    }
}
