package electrosphere.menu.mainmenu;

import electrosphere.engine.Globals;
import electrosphere.engine.loadingthreads.LoadingThread;
import electrosphere.engine.loadingthreads.LoadingThread.LoadingThreadType;
import electrosphere.menu.MenuGenerators;
import electrosphere.menu.WindowUtils;
import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Div;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.elementtypes.ClickableElement;
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaAlignment;
import electrosphere.renderer.ui.elementtypes.ContainerElement.YogaJustification;
import electrosphere.renderer.ui.elementtypes.Element;
import electrosphere.renderer.ui.events.ClickEvent;

/**
 * Menu generators for the title menu
 */
public class MenuGeneratorsTitleMenu {

    /**
     * Creates the main title menu
     * @return The menu element
     */
    public static Element createTitleMenu(){
        Div rVal = Div.createDiv();
        //top-bottom
        rVal.setJustifyContent(YogaJustification.Center);
        //left-right
        rVal.setAlignItems(YogaAlignment.Center);
        rVal.setAlignContent(YogaAlignment.Center);
        rVal.setFlexGrow(1.0f);

        //label (title)
        Label titleLabel = new Label(1.0f);
        titleLabel.setText("ORPG");
        rVal.addChild(titleLabel);

        //button (multiplayer)
        Button singleplayerButton = new Button();
        Label singleplayerLabel = new Label(1.0f);
        singleplayerLabel.setText("Singleplayer");
        singleplayerButton.addChild(singleplayerLabel);
        rVal.addChild(singleplayerButton);
        singleplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
            return false;
        }});

        //button (multiplayer)
        Button multiplayerButton = new Button();
        Label multiplayerLabel = new Label(1.0f);
        multiplayerLabel.setText("Multiplayer");
        multiplayerButton.addChild(multiplayerLabel);
        rVal.addChild(multiplayerButton);
        multiplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
            return false;
        }});

        //button (static level)
        Button staticLevelButton = new Button();
        Label staticLevelLabel = new Label(1.0f);
        staticLevelLabel.setText("Level Editor");
        staticLevelButton.addChild(staticLevelLabel);
        rVal.addChild(staticLevelButton);
        staticLevelButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            WindowUtils.replaceMainMenuContents(MenuGeneratorsLevelEditor.createLevelEditorTopMenu());
            return false;
        }});

        //button (options)
        Button optionsButton = new Button();
        Label optionsLabel = new Label(1.0f);
        optionsLabel.setText("Options");
        optionsButton.addChild(optionsLabel);
        rVal.addChild(optionsButton);
        optionsButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu());
            return false;
        }});

        //button (sp debug)
        Button uiDebugSPQuickstartButton = new Button();
        Label uiDebugSPQuickstartLabel = new Label(1.0f);
        uiDebugSPQuickstartLabel.setText("Debug SP Quickstart");
        uiDebugSPQuickstartButton.addChild(uiDebugSPQuickstartLabel);
        rVal.addChild(uiDebugSPQuickstartButton);
        uiDebugSPQuickstartButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            LoadingThread loadingThread = new LoadingThread(LoadingThreadType.DEBUG_RANDOM_SP_WORLD);
            Globals.loadingThreadsList.add(loadingThread);
            Globals.RUN_CLIENT = true;
            Globals.RUN_SERVER = true;
            loadingThread.start();
            return false;
        }});

        //button (ui testing)
        Button uiTestingButton = new Button();
        Label uiTestingLabel = new Label(1.0f);
        uiTestingLabel.setText("UI Testing");
        uiTestingButton.addChild(uiTestingLabel);
        rVal.addChild(uiTestingButton);
        uiTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
            WindowUtils.replaceMainMenuContents(MenuGeneratorsUITesting.createUITestMenu());
            return false;
        }});

        return rVal;
    }
}
