#include "Sdl3Poller.hpp"
#include "Sdl3Input.hpp"

void TSE::SDL3::Sdl3Poller::PollEvent(SDL_Event &event)
{
    switch (event.type)
    {
        case SDL_EVENT_KEY_DOWN:
            {
            int action = 1;
            if(event.key.repeat)
            {
                action = 2;
            }
            Sdl3Input::KeyCallback(event.key.key, action, event.key.mod);
            break;
            }
        case SDL_EVENT_KEY_UP:
            Sdl3Input::KeyCallback(event.key.key, 0, event.key.mod);
            break;
        case SDL_EVENT_MOUSE_BUTTON_DOWN:
            Sdl3Input::MouseButtonCallback(event.button.button, 1);
            break;
        case SDL_EVENT_MOUSE_BUTTON_UP:
            Sdl3Input::MouseButtonCallback(event.button.button, 0);
            break;
        case SDL_EVENT_MOUSE_MOTION:
            Sdl3Input::CursorPosCallback(event.motion.x, event.motion.y);
            break;
        case SDL_EVENT_MOUSE_WHEEL:
            Sdl3Input::ScrollCallback(event.wheel.x, event.wheel.y);
            break;
        case SDL_EVENT_TEXT_INPUT: // SDL_StartTextInput() must be called fist, before it takes text.
            Sdl3Input::CharCallback(event.text.text);
            break;
    }
}

void TSE::SDL3::Sdl3Poller::Init()
{
    Sdl3Input::Init();
}