package electrosphere.client.ui.menu.debug;

import electrosphere.engine.Globals;
import electrosphere.renderer.ui.imgui.ImGuiWindow;
import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback;
import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.gridded.GriddedDataCellManager;
import imgui.ImGui;

/**
 * Debug menu for gridded managers
 */
public class ImGuiGriddedManager {
    
    //window for viewing information about the ai state
    protected static ImGuiWindow griddedManagerWindow;

    /**
     * Creates the windows in this file
     */
    protected static void createGriddedManagerWindows(){
        ImGuiGriddedManager.createGriddedManagerWindow();
    }

    /**
     * Client scene entity view
     */
    protected static void createGriddedManagerWindow(){
        griddedManagerWindow = new ImGuiWindow("Gridded Manager");
        griddedManagerWindow.setCallback(new ImGuiWindowCallback() {
            @Override
            public void exec() {
                GriddedDataCellManager manager = null;
                if(Globals.realmManager != null && Globals.realmManager.first() != null){
                    Realm realm = Globals.realmManager.first();
                    if(realm.getDataCellManager() instanceof GriddedDataCellManager){
                        manager = (GriddedDataCellManager)realm.getDataCellManager();
                    }
                }

                if(manager != null){
                    if(manager.getLoadedCells() != null){
                        ImGui.text("Loaded Cells: " + manager.getLoadedCells().size());
                    }
                    if(manager.getCellPlayerlessFrameMap() != null){
                        ImGui.text("Playerless tracking map size: " + manager.getCellPlayerlessFrameMap().keySet().size());
                    }
                    ImGui.text("Cells cleaned last frame: " + manager.getNumCleaned());
                }
                
            }
        });
        griddedManagerWindow.setOpen(false);
        Globals.renderingEngine.getImGuiPipeline().addImGuiWindow(griddedManagerWindow);
    }

}
