package projectzombie.menu;

import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.display.DisplayRenderUI;
import projectzombie.entity.EntityParticle;
import projectzombie.input.types.InputGUI;
import projectzombie.menu.gui.GUIButton;
import projectzombie.menu.gui.GUIButtonGroup;
import projectzombie.menu.gui.GUI;
import projectzombie.menu.gui.GUISelectableDirection;
import projectzombie.menu.gui.GUILabel;
import projectzombie.menu.gui.components.ButtonBasic;
import projectzombie.menu.gui.components.ButtonSetting;
import projectzombie.menu.gui.components.GUIBackToMenu;
import projectzombie.menu.gui.components.OverlayBackground;
import projectzombie.settings.Settings;
import projectzombie.world.chunk.Chunk;

public class MenuSettings extends Menu
{
	private GUI gui;
	private Menu menuOld;
	
	public MenuSettings(Menu menuOld) {
		
		this.menuOld = menuOld;
		
		doGameloop = false;
		doGameRender = menuOld.doGameRender;
		showIngameGUI = menuOld.showIngameGUI;
		playerEmitsLight = menuOld.playerEmitsLight;
		keepMouse = false;
		
		GUIButtonGroup group = new GUIButtonGroup();
		group.setPos(new Vec2d(-1, 4));
		
		group.add(new ButtonSetting("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"), button -> {
			DisplayRenderUI.showFPS = !DisplayRenderUI.showFPS;
			button.setText("FPS: " + (DisplayRenderUI.showFPS ? "On" : "Off"));
			Settings.update();
		}));
		
		group.add(new ButtonSetting("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"),
				button ->
		{
			DisplayRenderUI.debug = !DisplayRenderUI.debug;
			button.setText("Debug mode: " + (DisplayRenderUI.debug ? "On" : "Off"));
			Settings.update();
		}));
		
		group.add(new ButtonSetting("Render distance: "+Chunk.RENDER_DISTANCE, button -> {
			Chunk.RENDER_DISTANCE += 1;
			if(Chunk.RENDER_DISTANCE > 8) {
				Chunk.RENDER_DISTANCE = 2;
			}
			button.setText("Render distance: "+Chunk.RENDER_DISTANCE);
			Settings.update();
		}));
		
		/*group.add(new ButtonSetting("Dynamic Lighting: " + (LightingManager.lightingMode == 0 ? "Fast" : "Fancy"),
				button ->
		{
			if(LightingManager.lightingMode == 0) {
				LightingManager.lightingMode = 1;
				
			} else {
				LightingManager.lightingMode = 0;
			}
			
			button.setText("Dynamic Lighting: " + (LightingManager.lightingMode == 0 ? "Fast" : "Fancy"));
		}));*/
		
		gui = new GUIBackToMenu(menuOld);
		input = new InputGUI(gui);
		
		if(doGameRender) {
			gui.add(new OverlayBackground());
		}
		
		gui.add(group);
		
		GUILabel labelSettings = new GUILabel();
		labelSettings.setText("Settings");
		labelSettings.setSize(new Vec2d(1, 1));
		labelSettings.setPos(new Vec2d(0, 6.8));
		gui.add(labelSettings);
		
		GUIButton buttonBack = new ButtonBasic("Back", new Vec2d(0, -8), button -> {
			Main.menu = menuOld;
		});
		
		group.get(group.size() - 1).setNeighbour(buttonBack, GUISelectableDirection.DOWN);
		buttonBack.setNeighbour(group.get(group.size() - 1), GUISelectableDirection.UP);
		
		gui.add(buttonBack);
		gui.setSelected(buttonBack);
	}

	@Override
	public void render() {
		gui.render();
	}
	
	@Override
	public void update() {
		super.update();
		this.menuOld.update();
	}

}
