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

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

    if (ws.released && ws.hover)
        *state = !*state;

    bool on = *state;

    RLDrawRectangleLines(rect.x, rect.y, rect.width, rect.height, { 0, 0, 0, 255 });
    
    RLColor toggle = on ? RLColor{ 26, 26, 26, 255 } : RLColor{ 38, 38, 38, 255 };

    RLDrawRectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2, toggle);

    if(label != nullptr){
        RLVector2 size = Font->MeasureText(label, 15);
        Font->DrawTextEX(label,
            { (rect.x + rect.width / 2) - size.x / 2, (rect.y + rect.height / 2) - (size.y / 2) },
            15, { 255, 255, 255, 255 });
    }
    return ws.released;
}

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