#include "input.h"

input_binding	load_default_binds(void) {
	InputBindings bindings = {
		.forward = {.is_mouse = false, .repeat = true, .bind = KEY_W},
		.backward = {.is_mouse = false, .repeat = true, .bind = KEY_S},
		.left = {.is_mouse = false, .repeat = true, .bind = KEY_A},
		.right = {.is_mouse = false, .repeat = true, .bind = KEY_D},
		.jump = {.is_mouse = false, .repeat = false, .bind = KEY_SPACE},
		.crouch = {.is_mouse = false, .repeat = true, .bind  = KEY_LEFT_CONTROL},
		.sprint = {.is_mouse = false, .repeat = true, .bind = KEY_LEFT_SHIFT},
	};
	return (bindings);
}

static bool	key_down(keybind_t *keybind) {
	if (keybind->is_mouse) {
		return IsMouseButtonDown(keybind->bind);
	}
	return (keybind->repeat ?
		IsKeyDown(keybind->bind) : IsKeyPressed(keybind->bind));
}

void	update_input_state(InputBindings *bindings, InputState *state) {
	state->forward	= key_down(&bindings->forward);
	state->backward	= key_down(&bindings->backward);
	state->left	= key_down(&bindings->left);
	state->right	= key_down(&bindings->right);
	state->jump	= key_down(&bindings->jump);
	state->crouch	= key_down(&bindings->crouch);
	state->sprint	= key_down(&bindings->sprint);
}
