#include "mr4th/mr4th_base.h"
#include <ncurses.h>

#include "mr4th/mr4th_base.c"

int main(){
  Arena *arena = arena_alloc();
  
  // initializes ncurses
  initscr();
  
  if (!has_colors()){
    goto no_color;
  }
  
  start_color();
  
  // settings
  noecho();
  cbreak();
  
  B32 animating = 1;
  
  // get size
  U32 window_x = 0;
  U32 window_y = 0;
  getmaxyx(stdscr, window_y, window_x);
  
  U32 window_stride = window_x;
  
  // color pairs
  struct ColorPairs{
    String8 text;
    S16 fore;
    S16 back;
  };
  struct ColorPairs color_pairs[] = {
    { str8_lit("  WHITE /   BLACK"), COLOR_WHITE  , COLOR_BLACK   },
    { str8_lit("    RED /   BLACK"), COLOR_RED    , COLOR_BLACK   },
    { str8_lit("  GREEN /   BLACK"), COLOR_GREEN  , COLOR_BLACK   },
    { str8_lit("   BLUE /   BLACK"), COLOR_BLUE   , COLOR_BLACK   },
    { str8_lit(" YELLOW /   BLACK"), COLOR_YELLOW , COLOR_BLACK   },
    { str8_lit("MAGENTA /   BLACK"), COLOR_MAGENTA, COLOR_BLACK   },
    { str8_lit("   CYAN /   BLACK"), COLOR_CYAN   , COLOR_BLACK   },
    
    { str8_lit("  BLACK /   WHITE"), COLOR_BLACK  , COLOR_WHITE   },
    { str8_lit("  BLACK /     RED"), COLOR_BLACK  , COLOR_RED     },
    { str8_lit("  BLACK /   GREEN"), COLOR_BLACK  , COLOR_GREEN   },
    { str8_lit("  BLACK /    BLUE"), COLOR_BLACK  , COLOR_BLUE    },
    { str8_lit("  BLACK /  YELLOW"), COLOR_BLACK  , COLOR_YELLOW  },
    { str8_lit("  BLACK / MAGENTA"), COLOR_BLACK  , COLOR_MAGENTA },
    { str8_lit("  BLACK /    CYAN"), COLOR_BLACK  , COLOR_CYAN    },
  };
  
  // print
  for (S16 i = 0; i < ArrayCount(color_pairs); i += 1){
    S16 pair_idx = i + 1;
    init_pair(pair_idx, color_pairs[i].fore, color_pairs[i].back);
    attron(COLOR_PAIR(pair_idx));
    printw("%.*s\n", (S32)color_pairs[i].text.size, color_pairs[i].text.str);
    attroff(pair_idx);
  }
  
  getch();
  endwin();
  
  if (0){ no_color:
    endwin();
    printf("no ncurses color support\n");
  }
  
  return(0);
}
