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

#ifdef TRACY_ENABLE
#include "tracy/Tracy.hpp"
#endif

void fps_overlay() {
#ifdef TRACY_ENABLE
    ZoneScoped;
#endif

    ImGuiIO& io = ImGui::GetIO();
    ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration
                           | ImGuiWindowFlags_AlwaysAutoResize
                           | ImGuiWindowFlags_NoSavedSettings
                           | ImGuiWindowFlags_NoFocusOnAppearing
                           | ImGuiWindowFlags_NoNav
                           | ImGuiWindowFlags_NoMove;

    const float pad = 10.0f;
    const ImGuiViewport* viewport = ImGui::GetMainViewport();
    ImVec2 pos(viewport->WorkPos.x + viewport->WorkSize.x - pad,
               viewport->WorkPos.y + pad);
    ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(1.0f, 0.0f));
    ImGui::SetNextWindowBgAlpha(0.65f);

    if (ImGui::Begin("##fps_overlay", nullptr, flags)) {
        ImGui::Text("%.1f FPS", io.Framerate);
        ImGui::Text("%.3f ms", 1000.0f / io.Framerate);
    }
    ImGui::End();
}
