package electrosphere.client.ui.menu.debug;

import org.joml.Vector3i;

import electrosphere.engine.Globals;
import electrosphere.entity.EntityUtils;
import electrosphere.renderer.ui.imgui.ImGuiWindow;
import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback;
import imgui.ImGui;

public class ImGuiChunkMonitor {

    /**
     * Num datapoints
     */
    public static final int PRESSURE_GRAPH_POINT_COUNT = 100;

    /**
     * Window for viewing chunk status on server and client
     */
    protected static ImGuiWindow chunkMonitorWindow;

    /**
     * Creates the windows in this file
     */
    protected static void createChunkMonitorWindows(){
        createChunkMonitorWindow();
    }

    /**
     * Client scene entity view
     */
    protected static void createChunkMonitorWindow(){
        chunkMonitorWindow = new ImGuiWindow("Chunk Monitor");

        chunkMonitorWindow.setCallback(new ImGuiWindowCallback() {
            @Override
            public void exec() {
                //ui framework text
                ImGui.text("Chunk Monitor");

                if(Globals.clientDrawCellManager != null){
                    Globals.clientDrawCellManager.updateStatus();
                    ImGui.text("Full res chunks: " + Globals.clientDrawCellManager.getMaxResCount());
                    ImGui.text("Terrain node count: " + Globals.clientDrawCellManager.getNodeCount());
                }
                if(Globals.clientBlockCellManager != null){
                    ImGui.text("Block node count: " + Globals.clientBlockCellManager.getNodeCount());
                }
                if(Globals.foliageCellManager != null){
                    ImGui.text("Foliage node count: " + Globals.foliageCellManager.getNodeCount());
                }
                if(ImGui.button("Break at chunk")){
                    if(Globals.foliageCellManager != null){
                        Vector3i absVoxelPos = Globals.clientWorldData.convertRealToAbsoluteVoxelSpace(EntityUtils.getPosition(Globals.playerEntity));
                        Globals.foliageCellManager.addBreakPoint(absVoxelPos);
                    }
                }
            }
        });
        chunkMonitorWindow.setOpen(false);
        Globals.renderingEngine.getImGuiPipeline().addImGuiWindow(chunkMonitorWindow);
    }
}
