//
// Created by spenc on 5/21/2025.
//

#include "Viewport.h"
#include <imgui.h>

namespace OX
{
    int Viewport::s_nextID = 0;

    void Viewport::Draw(Core &core) const
    {
        // Construct title
        std::string title = m_name + " (" + std::to_string(m_id) + ")";
        GLuint textureID = core.GetRenderer().GetRenderTexture(); // You must define this method


        // Remove window padding
        ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));

        // Begin full viewport window
        ImGui::Begin(title.c_str(), nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);

        // Get size of available region
        ImVec2 viewportSize = ImGui::GetContentRegionAvail();

        // === Fullscreen image ===
        if (textureID != 0) {
            ImGui::Image(textureID, viewportSize, ImVec2(0, 1), ImVec2(1, 0));
        } else {
            ImGui::Text("No Render Target.");
        }


        ImGui::End();
        ImGui::PopStyleVar(); // Restore padding

        core.GetRenderer().ResizeTarget(viewportSize.x, viewportSize.y);
    }
};
