#include "empty_state.h"
#include "tokens.h"
#include "imgui.h"

void empty_state(const char* icon, const char* title, const char* description) {
    ImVec2 avail = ImGui::GetContentRegionAvail();

    // Altura estimada del bloque: icon (2x font) + title (1x) + description (1x)
    // + spacings. Se centra verticalmente dejando vertical padding arriba.
    const float line = ImGui::GetTextLineHeight();
    float block_h = line * 2.0f + fn_tokens::spacing::md + line;
    if (description && *description) block_h += line + fn_tokens::spacing::xs;

    if (avail.y > block_h) {
        ImGui::Dummy(ImVec2(1.0f, (avail.y - block_h) * 0.5f));
    }

    // Icon (centrado, 2x tamaño vía font scale)
    ImGui::PushStyleColor(ImGuiCol_Text, fn_tokens::colors::text_muted);
    ImGui::SetWindowFontScale(2.0f);
    ImVec2 icon_size = ImGui::CalcTextSize(icon);
    float icon_x = (avail.x - icon_size.x) * 0.5f;
    if (icon_x < 0) icon_x = 0;
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + icon_x);
    ImGui::TextUnformatted(icon);
    ImGui::SetWindowFontScale(1.0f);
    ImGui::PopStyleColor();

    ImGui::Dummy(ImVec2(1.0f, fn_tokens::spacing::sm));

    // Title (centrado)
    ImVec2 title_size = ImGui::CalcTextSize(title);
    float title_x = (avail.x - title_size.x) * 0.5f;
    if (title_x < 0) title_x = 0;
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + title_x);
    ImGui::TextUnformatted(title);

    // Description (centrado, muted)
    if (description && *description) {
        ImGui::Dummy(ImVec2(1.0f, fn_tokens::spacing::xs));
        ImGui::PushStyleColor(ImGuiCol_Text, fn_tokens::colors::text_muted);
        ImVec2 desc_size = ImGui::CalcTextSize(description);
        float desc_x = (avail.x - desc_size.x) * 0.5f;
        if (desc_x < 0) desc_x = 0;
        ImGui::SetCursorPosX(ImGui::GetCursorPosX() + desc_x);
        ImGui::TextUnformatted(description);
        ImGui::PopStyleColor();
    }
}
