#include "core/sidebar.h"
#include "imgui.h"

static bool s_sidebar_was_open = false;

bool sidebar_begin(const char* title, bool* open, float width) {
    if (!*open) {
        s_sidebar_was_open = false;
        if (ImGui::Button(">")) {
            *open = true;
        }
        return false;
    }

    s_sidebar_was_open = true;
    ImGui::SetNextWindowSize(ImVec2(width, 0.0f), ImGuiCond_Always);
    ImGui::Begin(title, open, ImGuiWindowFlags_NoCollapse);
    return true;
}

void sidebar_end() {
    if (s_sidebar_was_open) {
        ImGui::End();
    }
}
