// src/render/player.cpp
#include "player.h"
#include "../assets/character_walk_frames.h"
#include "../assets/character_run_frames.h"
#include "../assets/character_crawl_frames.h"
#include <cstdio>

void draw_character(int x, int y, MovementType movement, int frame_index) {
    const char **character = nullptr;
    int character_height = 0;
    int total_frames = 0;

    switch (movement) {
    case MovementType::Walk:
        total_frames = CHARACTER_WALK_FRAME_COUNT;
        if (frame_index < 0 || frame_index >= total_frames)
            frame_index = 0;
        character = CHARACTER_WALK_FRAMES[frame_index];
        character_height = CHARACTER_WALK_FRAME_HEIGHT;
        break;

    case MovementType::Run:
        total_frames = CHARACTER_RUN_FRAME_COUNT;
        if (frame_index < 0 || frame_index >= total_frames)
            frame_index = 0;
        character = CHARACTER_RUN_FRAMES[frame_index];
        character_height = CHARACTER_RUN_FRAME_HEIGHT;
        break;

    case MovementType::Crawl1:
        total_frames = CHARACTER_CRAWL1_FRAME_COUNT;
        if (frame_index < 0 || frame_index >= total_frames)
            frame_index = 0;
        character = CHARACTER_CRAWL1_FRAMES[frame_index];
        character_height = CHARACTER_CRAWL1_FRAME_HEIGHT;
        break;

    case MovementType::Crawl2:
        total_frames = CHARACTER_CRAWL2_FRAME_COUNT;
        if (frame_index < 0 || frame_index >= total_frames)
            frame_index = 0;
        character = CHARACTER_CRAWL2_FRAMES[frame_index];
        character_height = CHARACTER_CRAWL2_FRAME_HEIGHT;
        break;
    }

    for (int i = 0; i < character_height; i++) {
        printf("\033[%d;%dH%s", y + i + 1, x + 1, character[i]);
    }
    fflush(stdout);
}
