#ifndef UI_H
#define UI_H

#include "SDL_events.h"
#include "aliases/aliases.h"
#include "window.h"
#include <stdbool.h>

#define MAX_UI_ELEMENTS 4096

#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 40

#define NODE_WIDTH 70
#define NODE_HEIGHT 20

typedef enum ui_elem_type ui_elem_type_t;
typedef struct ui_elem ui_elem_t;
typedef struct ui_ctx ui_ctx_t;

enum ui_elem_type {
  UI_ELEM_NODE,
  UI_ELEM_BUTTON,

  COUNT_UI_ELEM,
};

struct ui_elem {
  u64 id;
  rect_t rect;
  ui_elem_type_t type;
};

typedef struct ui_elem_colours ui_elem_colours_t;
struct ui_elem_colours {
  colour_t fill;
  colour_t border;
};

struct ui_ctx {
  u64 count;
  i64 hovered;
  i64 active;
  i32 mouse_x;
  i32 mouse_y;
  i32 rel_x;
  i32 rel_y;
  bool mouse_down;
  bool mouse_up;
  const window_t *wnd;
  ui_elem_t elements[MAX_UI_ELEMENTS];
};

void init_ui_ctx(ui_ctx_t *ctx);
void reset_ui_ctx(ui_ctx_t *ctx);
void handle_ui_events(const window_t *wnd, ui_ctx_t *ctx,
                      const SDL_Event *event);
bool button(const window_t *wnd, ui_ctx_t *ctx, rect_t rect,
            ui_elem_colours_t colours);
rect_t node(const window_t *wnd, ui_ctx_t *ctx, rect_t rect,
            ui_elem_colours_t colours);

#endif // !UI_H