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

public class UICallbacks : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    private bool _isHovering;
    private bool _hoverActionActivated;
    private float _hoveredTime;
    private float _timeBeforeHoverActivate = 1.5f;
    public UnityEvent MouseHover;
    public UnityEvent MouseHoverEnd;

    public void OnPointerEnter(PointerEventData eventData)
    {
        _hoverActionActivated = false;
        _isHovering = true;
        _hoveredTime = 0;
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        _isHovering = false;
        MouseHoverEnd.Invoke();
    }

    private void Update()
    {
        if (_isHovering && !_hoverActionActivated)
        {
            _hoveredTime += Time.deltaTime;
            if (_hoveredTime >= _timeBeforeHoverActivate)
            {
                _hoverActionActivated = true;
                MouseHover.Invoke();
            }
        }
    }

    public void SetTooltipText(string text)
    {
        ModelViewerInterface.GetInstance().Tooltip.SetAsLastSibling();
        ModelViewerInterface.GetInstance().TooltipText.text = text;
    }
}
