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

bool ClearAreaEditor::renderComponent(flecs::entity entity, ClearAreaComponent& clearArea)
{
    bool modified = false;
    
    if (ImGui::CollapsingHeader("Clear Area", ImGuiTreeNodeFlags_DefaultOpen)) {
        ImGui::Indent();
        
        ImGui::Text("Area Size: %dx%dx%d", clearArea.getSizeX(), clearArea.getSizeY(), clearArea.getSizeZ());
        
        int minPos[3] = { clearArea.minX, clearArea.minY, clearArea.minZ };
        if (ImGui::InputInt3("Min (X/Y/Z)", minPos)) {
            clearArea.minX = minPos[0];
            clearArea.minY = minPos[1];
            clearArea.minZ = minPos[2];
            modified = true;
        }
        
        int maxPos[3] = { clearArea.maxX, clearArea.maxY, clearArea.maxZ };
        if (ImGui::InputInt3("Max (X/Y/Z)", maxPos)) {
            clearArea.maxX = maxPos[0];
            clearArea.maxY = maxPos[1];
            clearArea.maxZ = maxPos[2];
            modified = true;
        }
        
        ImGui::Separator();
        ImGui::Text("Clear Options:");
        
        if (ImGui::Checkbox("Clear Cells (Walls/Floors)", &clearArea.clearCells)) modified = true;
        if (ImGui::Checkbox("Clear Furniture", &clearArea.clearFurniture)) modified = true;
        if (ImGui::Checkbox("Clear Roofs", &clearArea.clearRoofs)) modified = true;
        if (ImGui::Checkbox("Clear Rooms", &clearArea.clearRooms)) modified = true;
        
        ImGui::Separator();
        
        // Status
        if (clearArea.processed) {
            ImGui::TextColored(ImVec4(0, 1, 0, 1), "Status: Processed");
        } else {
            ImGui::TextColored(ImVec4(1, 1, 0, 1), "Status: Pending");
        }
        
        if (ImGui::Button("Clear Area Now")) {
            clearArea.markDirty();
            modified = true;
        }
        
        ImGui::Unindent();
    }
    
    return modified;
}
