local ffi = require("ffi")
local C = ffi.C
local core = require("pxl8.core")

local input = {}

function input.key_down(key)
    return C.pxl8_key_down(core.input, key)
end

function input.key_pressed(key)
    return C.pxl8_key_pressed(core.input, key)
end

function input.key_released(key)
    return C.pxl8_key_released(core.input, key)
end

function input.mouse_wheel_x()
    return C.pxl8_mouse_wheel_x(core.input)
end

function input.mouse_wheel_y()
    return C.pxl8_mouse_wheel_y(core.input)
end

function input.mouse_x()
    return C.pxl8_mouse_x(core.input)
end

function input.mouse_y()
    return C.pxl8_mouse_y(core.input)
end

function input.mouse_dx()
    return C.pxl8_mouse_dx(core.input)
end

function input.mouse_dy()
    return C.pxl8_mouse_dy(core.input)
end

function input.get_mouse_pos()
    return C.pxl8_mouse_x(core.input), C.pxl8_mouse_y(core.input)
end

function input.mouse_pressed(button)
    return C.pxl8_mouse_pressed(core.input, button)
end

function input.mouse_released(button)
    return C.pxl8_mouse_released(core.input, button)
end

function input.set_relative_mouse_mode(enabled)
    C.pxl8_set_relative_mouse_mode(core.sys, enabled)
end

function input.center_cursor()
    C.pxl8_center_cursor(core.sys)
end

function input.set_cursor(cursor_type)
    local cursor_enum
    if cursor_type == "arrow" then
        cursor_enum = C.PXL8_CURSOR_ARROW
    elseif cursor_type == "hand" then
        cursor_enum = C.PXL8_CURSOR_HAND
    else
        cursor_enum = C.PXL8_CURSOR_ARROW
    end
    C.pxl8_set_cursor(core.sys, cursor_enum)
end

return input
