#include "ProgressBar.hpp"
#include "Renderer.hpp"

namespace GModTeach {
namespace UI {

ProgressBar::ProgressBar(SDL_Rect bounds)
    : m_bounds(bounds), m_progress(0.0f) {}

void ProgressBar::SetProgress(float value) {
    m_progress = std::clamp(value, 0.0f, 1.0f);
}

void ProgressBar::Draw(SDL_Renderer* renderer, TTF_Font* font) const {
    if (!renderer) return;

    // abkground draww
    SDL_SetRenderDrawColor(renderer, CLR_GMOD_BLUE.r, CLR_GMOD_BLUE.g, CLR_GMOD_BLUE.b, CLR_GMOD_BLUE.a);
    SDL_RenderFillRect(renderer, &m_bounds);

    // darw border
    SDL_SetRenderDrawColor(renderer, CLR_WHITE.r, CLR_WHITE.g, CLR_WHITE.b, CLR_WHITE.a);
    SDL_RenderDrawRect(renderer, &m_bounds);

    // fill progress bar based on m_progress
    if (m_progress > 0.0f) {
        int fillWidth = static_cast<int>(m_bounds.w * m_progress);
        SDL_Rect fillRect = { m_bounds.x, m_bounds.y, fillWidth, m_bounds.h };
        SDL_SetRenderDrawColor(renderer, CLR_WHITE.r, CLR_WHITE.g, CLR_WHITE.b, CLR_WHITE.a);
        SDL_RenderFillRect(renderer, &fillRect);
    }

    // status text draw
    if (font && !m_statusText.empty()) {
        Renderer::DrawText(renderer, font, m_statusText, m_bounds.x, m_bounds.y + m_bounds.h + 6, CLR_WHITE);
    }
}

} 
} 
