#if USING_MRTK3 && USING_XRI

using UnityEngine.InputSystem;
using UnityEngine;
using UnityEngine.Events;

namespace SimplifyXR
{
    public class MRTK3GlobalTapMapping : MonoBehaviour, IGlobalTapMapping
    {
        [SerializeField]
        private InputActionReference leftHandReference;
        [SerializeField]
        private InputActionReference rightHandReference;

        public UnityEvent AirTap;
        UnityEvent IGlobalTapMapping.AirTap => AirTap;


        private void Start()
        {
            leftHandReference.action.performed += ProcessHand;
            rightHandReference.action.performed += ProcessHand;
        }
    
        private void ProcessHand(InputAction.CallbackContext ctx)
        {
            if (ctx.ReadValue<float>() > 0.95)
            {
                AirTap?.Invoke();
            }
        }

        private void OnDestroy()
        {
            leftHandReference.action.performed -= ProcessHand;
            rightHandReference.action.performed -= ProcessHand;
        }
    }

}
#endif
