using UnityEngine;
using UnityEngine.InputSystem;

public class InputHandler : MonoBehaviour
{
    private Vector2 lookDelta;
    private float zoomDelta;
    private Vector2 mousePosition;
    private bool isRightMouseHeld;
    private bool isMiddleMouseHeld;
    private bool isLeftMouseHeld;
    private bool isAltHeld;
    private bool wasOrbitActiveLastFrame;

    public void OnLook(InputValue value)
    {
        lookDelta = value.Get<Vector2>();
    }

    public void OnZoom(InputValue value)
    {
        zoomDelta = value.Get<float>();
    }

    public void OnMousePosition(InputValue value)
    {
        mousePosition = value.Get<Vector2>();
    }

    public void OnRightMouse(InputValue value)
    {
        isRightMouseHeld = value.isPressed;
    }

    public void OnMiddleMouse(InputValue value)
    {
        isMiddleMouseHeld = value.isPressed;
    }

    public void OnLeftMouse(InputValue value)
    {
        isLeftMouseHeld = value.isPressed;
    }

    public void OnAlt(InputValue value)
    {
        isAltHeld = value.isPressed;
    }

    public Vector2 GetLookDelta() => lookDelta;
    public float GetZoomDelta() => zoomDelta;
    public Vector2 GetMousePosition() => mousePosition;
    public bool IsRightMouseHeld() => isRightMouseHeld;
    public bool IsMiddleMouseHeld() => isMiddleMouseHeld;
    public bool IsOrbitActive() => isAltHeld && isLeftMouseHeld;
    public bool IsOrbitStarting()
    {
        bool isOrbitActive = IsOrbitActive();
        bool isStarting = isOrbitActive && !wasOrbitActiveLastFrame;
        wasOrbitActiveLastFrame = isOrbitActive;
        return isStarting;
    }
}