package zenith.zov.client.modules.impl.render;

import com.darkmagician6.eventapi.EventTarget;
import zenith.zov.Zenith;
import zenith.zov.base.events.impl.render.EventRenderScreen;
import zenith.zov.client.modules.api.Category;
import zenith.zov.client.modules.api.Module;
import zenith.zov.client.modules.api.ModuleAnnotation;
import zenith.zov.utility.render.display.base.UIContext;

@ModuleAnnotation(
    name = "Menu",
    category = Category.RENDER,
    description = "Cheat menu"
)
public final class Menu extends Module {
    public static final Menu INSTANCE = new Menu();

    private Menu() {
        this.setKeyCode(344);
    }

    @Override
    public void onEnable() {
        if (mc.world == null) {
            this.setEnabled(false);
        } else if (mc.currentScreen != Zenith.getInstance().getMenuScreen()) {
            mc.setScreen(Zenith.getInstance().getMenuScreen());
            super.onEnable();
        }
    }

    @Override
    public void onDisable() {
        super.onDisable();
    }

    @Override
    public void setKeyCode(int keyCode) {
        if (keyCode != -1) {
            super.setKeyCode(keyCode);
        }
    }

    @EventTarget
    public void render2d(EventRenderScreen eventRender2D) {
        UIContext uiContext = eventRender2D.getContext();
        Zenith.getInstance().getMenuScreen().renderTop(uiContext, (float)uiContext.getMouseX(), (float)uiContext.getMouseY());
        if (Zenith.getInstance().getMenuScreen().isFinish()) {
            this.toggle();
        }
    }
}
