//
// Created by sebastian on 02.08.26.
//

#ifndef COLORRACE_MOUSE_H
#define COLORRACE_MOUSE_H
#include <unordered_set>

#include "MouseButton.h"
#include "glm/vec2.hpp"


namespace engine {
    class Window;

    class Mouse {
    public:
        explicit Mouse(Window& window);
        bool isButtonDown(MouseButton button) const;
        bool isClickEvent(MouseButton button) const;
        bool isReleaseEvent(MouseButton button) const;
        float getX(bool ndc) const;
        float getY(bool ndc) const;
        float getDX() const;
        float getDY() const;
        float getScroll() const;
        void update();
        glm::vec2 getXY(bool ndc) const;
    private:
        std::unordered_set<int> buttonsDown;
        std::unordered_set<int> buttonsClickedThisFrame;
        std::unordered_set<int> buttonsReleasedThisFrame;

        float x = 0.0f, y = 0.0f;
        float dx = 0.0f, dy = 0.0f;
        float scroll = 0.0f;
        float lastX = 0.0f, lastY = 0.0f;

        void reportButtonClick(int button);
        void reportButtonRelease(int button);
        void updateDetlas();

        static void addMoveListener(Window& window);
        static void addScrollListener(Window& window);
        static void addClickListener(Window& window);

        static int MouseButtonToInt(MouseButton button);
    };
}


#endif //COLORRACE_MOUSE_H
