package eu.jonahbauer.wizard.client.libgdx.actions.overlay;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import eu.jonahbauer.wizard.client.libgdx.actors.CardActor;
import eu.jonahbauer.wizard.client.libgdx.screens.GameScreen;
import eu.jonahbauer.wizard.common.model.Card;
import org.jetbrains.annotations.NotNull;

import java.util.EnumMap;

public class PlayChangelingOverlay extends Overlay implements InteractionOverlay {
    public PlayChangelingOverlay(@NotNull GameScreen gameScreen, long timeout) {
        super(gameScreen, timeout);
    }

    @Override
    public Actor createContent() {
        var root = new VerticalGroup().columnCenter().space(10);

        var prompt = new Label(messages.get("game.overlay.play_changeling.prompt"), skin);
        var cardGroup = new HorizontalGroup().space(20);

        var wizard = new CardActor(Card.CHANGELING_WIZARD, atlas);
        var jester = new CardActor(Card.CHANGELING_JESTER, atlas);
        cardGroup.addActor(wizard);
        cardGroup.addActor(jester);

        cardGroup.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                if (isClosing()) return;
                var target = event.getTarget();
                if (target == wizard) {
                    screen.onCardClicked(Card.CHANGELING_WIZARD);
                } else if (target == jester) {
                    screen.onCardClicked(Card.CHANGELING_JESTER);
                }
            }
        });

        root.addActor(prompt);
        root.addActor(cardGroup);

        var cancel = new TextButton(messages.get("game.overlay.play_changeling.cancel"), skin, "simple");
        cancel.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                close();
            }
        });
        root.addActor(cancel);

        return root;
    }
}
