#include <raylib.h>
#include <stdio.h>

#define SKILL_COUNT 20
#define ATTRIBUTES_COUNT 6

char *attributes_names[ATTRIBUTES_COUNT] = {
    "STRENGTH","AGILITY","VITALITY","INTELLECT","RESOLVE","KARMA"
};

char *skill_names[SKILL_COUNT] = {
    "Mining","Combat","Trading","Farming","Crafting","Building","Forestry","Enchanting","Alchemy","Fishing",
    "Casting","Cooking","Taming","Stealth","Music","Exploration","Excavation","Archery","Defense","Agility"
};

void SetupCharacter() {

    int skills[SKILL_COUNT] = {0};
    int attributes[ATTRIBUTES_COUNT] = {0};

    int selected_skill = 0;
    int selected_attr = 0;
    int mode = 0; // 0 = Skills, 1 = Attributes

    InitWindow(800, 600, "RPG Menü");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {

        // INPUT
        if (IsKeyPressed(KEY_TAB)) mode = !mode;

        if (IsKeyPressed(KEY_DOWN)) {
            if (mode == 0) selected_skill = (selected_skill + 1) % SKILL_COUNT;
            else selected_attr = (selected_attr + 1) % ATTRIBUTES_COUNT;
        }

        if (IsKeyPressed(KEY_UP)) {
            if (mode == 0) selected_skill = (selected_skill - 1 + SKILL_COUNT) % SKILL_COUNT;
            else selected_attr = (selected_attr - 1 + ATTRIBUTES_COUNT) % ATTRIBUTES_COUNT;
        }

        if (IsKeyPressed(KEY_RIGHT)) {
            if (mode == 0) skills[selected_skill]++;
            else attributes[selected_attr]++;
        }

        if (IsKeyPressed(KEY_LEFT)) {
            if (mode == 0) skills[selected_skill]--;
            else attributes[selected_attr]--;
        }

        // DRAW
        BeginDrawing();
        ClearBackground(BLACK);

        DrawText("RPG MENU", 300, 20, 30, WHITE);

        // Attributes
        DrawText("ATTRIBUTES", 50, 80, 20, mode == 1 ? YELLOW : GRAY);
        for (int i = 0; i < ATTRIBUTES_COUNT; i++) {
            Color col = (i == selected_attr && mode == 1) ? YELLOW : WHITE;

            DrawText(TextFormat("%s: %d", attributes_names[i], attributes[i]),
                     50, 110 + i * 25, 20, col);
        }

        // Skills
        DrawText("SKILLS", 400, 80, 20, mode == 0 ? YELLOW : GRAY);
        for (int i = 0; i < SKILL_COUNT; i++) {
            Color col = (i == selected_skill && mode == 0) ? YELLOW : WHITE;

            DrawText(TextFormat("%s: %d", skill_names[i], skills[i]),
                     400, 110 + i * 25, 20, col);
        }

        EndDrawing();
    }

    CloseWindow();
    return ;
}
