#include "../UIFramework.h"
#include "../../Backend/Font/FontManager.h"
#include "raylib.h"

bool WidgetManager::Button(const char* label, RLRectangle rect, bool disabled) {
    auto ws = BeginWidget(rect);
    auto r = Render::Get();
    auto Font = Font::Get();

    RLDrawRectangleLines(rect.x, rect.y, rect.width, rect.height, { 0, 0, 0, 255 });
    RLDrawRectangleLines(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2, { 50, 50, 50, 255 });

    RLVector2 size = Font->MeasureText(label, 18);

    if (ws.pressed)      r->Gradient({ rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4 }, RLColor{ 30, 30, 30, 255 }, RLColor{ 20, 20, 20, 255 }, true, true);
    else if (ws.hover)   r->Gradient({ rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4 }, RLColor{ 39, 39, 39, 255 }, RLColor{ 35, 35, 35, 255 }, true, true);
    else                 r->Gradient({ rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4 }, RLColor{ 34, 34, 34, 255 }, RLColor{ 30, 30, 30, 255 }, true, true);

    
    Font->DrawTextEX(label, { (rect.x + rect.width / 2) - size.x / 2, (rect.y + rect.height / 2) - (size.y / 2) }, 18, disabled ? RLColor{ 128, 128, 128, 255 } :RLColor{ 255, 255, 255, 255 },0);

    return ws.released;
}

bool Framework::Button(const char* label, RLRectangle Rect, bool disabled) {
    return WidgetManager::Get()->Button(label, Rect, disabled);
}