package eu.jonahbauer.wizard.client.libgdx.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.WizardGame;

public class CreateGameScreen extends MenuScreen {
    TextButton backButton;
    TextButton continueButton;

    TextField option1;
    TextField option2;
    TextField option3;
    TextField option4;
    TextField option5;
    TextField option6;

    ClickListener listener = new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            var target = event.getListenerActor();
            if (target == backButton) {
                game.setScreen(new SessionListScreen(game));
                sfxClick();
            } else if (target == continueButton) {
                game.setScreen(new WaitingScreen(game));
                sfxClick();
            }
        }
    };

    public CreateGameScreen(WizardGame game) {
        super(game);
    }

    @Override
    public void show() {
        super.show();

        backButton = new TextButton("Zurück", skin);
        backButton.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.18f);
        backButton.setSize(120, backButton.getHeight());
        continueButton = new TextButton("Fortfahren", skin);
        continueButton.setPosition(WizardGame.WIDTH * 0.7f - continueButton.getWidth(), WizardGame.HEIGHT * 0.18f);

        option1 = new TextField("1", skin);
        option1.setPosition(WizardGame.WIDTH * 0.3f, WizardGame.HEIGHT * 0.6f);
        option1.setSize(250, continueButton.getHeight());
        option2 = new TextField("2", skin);
        option2.setPosition(option1.getX(), option1.getY() - WizardGame.HEIGHT * 0.12f);
        option2.setSize(250, continueButton.getHeight());
        option3 = new TextField("3", skin);
        option3.setPosition(option2.getX(), option2.getY() - WizardGame.HEIGHT * 0.12f);
        option3.setSize(250, continueButton.getHeight());

        option4 = new TextField("4", skin);
        option4.setPosition(WizardGame.WIDTH * 0.65f - option4.getWidth(), option1.getY());
        option4.setSize(250, continueButton.getHeight());
        option5 = new TextField("5", skin);
        option5.setPosition(option4.getX(), option2.getY());
        option5.setSize(250, continueButton.getHeight());
        option6 = new TextField("6", skin);
        option6.setPosition(option4.getX(), option3.getY());
        option6.setSize(250, continueButton.getHeight());

        Gdx.input.setInputProcessor(stage);
        stage.addActor(backButton);
        stage.addActor(continueButton);
        stage.addActor(option1);
        stage.addActor(option2);
        stage.addActor(option3);
        stage.addActor(option4);
        stage.addActor(option5);
        stage.addActor(option6);

        backButton.addListener(listener);
        continueButton.addListener(listener);
    }

    @Override
    protected void renderInternal(float delta) {}
}
