#pragma once

#include "basic.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "render_data.h"
#include "user_interface.h"
#include "camera.h"
#include "timer.h"
#include "frame_buffer.h"
#include "vertex_buffer.h"
#include "uniform_buffer.h"
#include "texture.h"
#include "shaders.h"


struct Renderer {
  Shader shader;
  Shader alt_shader;
  Frame_Buffer frame_buffer;
  Vertex_Buffer vertex_buffer;
  Uniform_Buffer uniform_buffer;
  Texture texture;
  Mesh mesh;
  Matrix4 view_matrix = Matrix4(1.0f);
  Matrix4 projection_matrix = Matrix4(1.0f);
  User_Interface user_interface;
  Render_Data render_data;
  Camera camera;
  bool mouse_lock = false;
  s32 mouse_x_position = 0;
  s32 mouse_y_position = 0;
  Timer timer;
  f64 last_tick_time = 0.0;
};


bool init_renderer(Renderer *renderer, u32 width, u32 height);
void set_renderer_size(Renderer *renderer, u32 width, u32 height);
void draw_renderer(Renderer *renderer);
void upload_renderer_data(Renderer *renderer, Mesh *vertex_data);
void cleanup_renderer(Renderer *renderer);

// Event handling
void handle_key_events(Renderer *renderer, s32 key, s32 scancode, s32 action, s32 mods);
void handle_movement_keys(Renderer *renderer);
void handle_mouse_position_events(Renderer *renderer, f64 x_pos, f64 y_pos);
void handle_mouse_button_events(Renderer *renderer, s32 button, s32 action, s32 mods);
