#include "RoomWindowsEditor.hpp"
#include "../components/CellGrid.hpp"
#include <imgui.h>

bool RoomWindowsEditor::renderComponent(flecs::entity entity, RoomWindowsComponent& windows)
{
    bool modified = false;
    
    if (ImGui::CollapsingHeader("Room Windows", ImGuiTreeNodeFlags_DefaultOpen)) {
        ImGui::Indent();
        
        // Linked room
        ImGui::Text("Linked Room:");
        if (windows.room.is_alive()) {
            ImGui::Text("  Entity ID: %llu", windows.room.id());
            if (windows.room.has<RoomComponent>()) {
                const auto& room = windows.room.get<RoomComponent>();
                ImGui::Text("  Type: %s", room.roomType.c_str());
            }
        } else {
            ImGui::TextDisabled("  (Not set)");
        }
        
        ImGui::Separator();
        
        // Floor Y
        if (ImGui::InputInt("Floor Y", &windows.floorY)) {
            modified = true;
        }
        
        ImGui::Separator();
        
        // Window sides
        ImGui::Text("Create windows on sides:");
        if (ImGui::Checkbox("Z- (North)", &windows.windowZNeg)) modified = true;
        if (ImGui::Checkbox("Z+ (South)", &windows.windowZPos)) modified = true;
        if (ImGui::Checkbox("X- (West)", &windows.windowXNeg)) modified = true;
        if (ImGui::Checkbox("X+ (East)", &windows.windowXPos)) modified = true;
        
        // Quick presets
        ImGui::Separator();
        ImGui::Text("Quick Presets:");
        if (ImGui::Button("All Sides")) {
            windows.setAllSides(true);
            modified = true;
        }
        ImGui::SameLine();
        if (ImGui::Button("None")) {
            windows.setAllSides(false);
            modified = true;
        }
        
        ImGui::Separator();
        
        // Status
        if (windows.processed) {
            ImGui::TextColored(ImVec4(0, 1, 0, 1), "Status: Processed");
        } else {
            ImGui::TextColored(ImVec4(1, 1, 0, 1), "Status: Pending");
        }
        
        if (ImGui::Button("Reprocess Windows")) {
            windows.markDirty();
            modified = true;
        }
        
        ImGui::Unindent();
    }
    
    return modified;
}
