using System;
using UnityEngine;

namespace OvrLip
{
	internal static class OVRTouchpad
	{
		public static void Create()
		{
		}

		public static void Update()
		{
			if (NInput.GetMouseButtonDown(0))
			{
				OVRTouchpad.moveAmountMouse = Input.mousePosition;
			}
			else if (NInput.GetMouseButtonUp(0))
			{
				OVRTouchpad.moveAmountMouse -= Input.mousePosition;
				OVRTouchpad.HandleInputMouse(ref OVRTouchpad.moveAmountMouse);
			}
		}

		public static void OnDisable()
		{
		}

		private static void HandleInputMouse(ref Vector3 move)
		{
			if (move.magnitude < OVRTouchpad.minMovMagnitudeMouse)
			{
				OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.SingleTap);
			}
			else
			{
				move.Normalize();
				if (Mathf.Abs(move.x) > Mathf.Abs(move.y))
				{
					if (move.x > 0f)
					{
						OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Left);
					}
					else
					{
						OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Right);
					}
				}
				else if (move.y > 0f)
				{
					OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Down);
				}
				else
				{
					OVRMessenger.Broadcast<OVRTouchpad.TouchEvent>("Touchpad", OVRTouchpad.TouchEvent.Up);
				}
			}
		}

		private static Vector3 moveAmountMouse;

		private static float minMovMagnitudeMouse = 25f;

		private static OVRTouchpadHelper touchpadHelper = new GameObject("OVRTouchpadHelper").AddComponent<OVRTouchpadHelper>();

		public enum TouchEvent
		{
			SingleTap,
			DoubleTap,
			Left,
			Right,
			Up,
			Down
		}
	}
}
