package com.ghost.technic;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.ghost.technic.server.card.keyword.Keyword;
import com.ghost.technic.server.card.playable.PlayableCard;
import com.ghost.technic.server.card.playable.usable.impl.CreatureCard;

import java.util.stream.Collectors;

public class CardActor extends Table {
    private final PlayableCard card;

    public CardActor(PlayableCard card, Skin skin) {
        this.card = card;
        setBackground("default-round");
        pad(10);

        Label nameLabel = new Label(card.getName(), skin);
        add(nameLabel).row();

        // Example: add keyword display
        if (card instanceof CreatureCard creature) {
            for (Keyword k : creature.getKeywords()) {
                Label kwLabel = new Label(k.toString(), skin);
                add(kwLabel).row();
                addTooltip(kwLabel, k.getKeywordAbility().name()); // TODO: add tooltip details
            }
        }
    }

    private void addTooltip(Actor actor, String text) {
        Tooltip<Label> tooltip = new Tooltip<>(new Label(text, getSkin()));
        TooltipManager.getInstance().initialTime = 0.4f;
        tooltip.setInstant(true);
        tooltip.setAlways(true);
        actor.addListener(tooltip);
    }
}


//public class CardActor extends Image {
//    private final PlayableCard card;
//
//    public CardActor(PlayableCard card, Skin skin) {
//        super(skin.getDrawable("card-default")); // Replace with card sprite
//        this.card = card;
//
//        setSize(100, 150); // Default size
//        addListener(new InputListener() {
//            @Override
//            public boolean mouseMoved(InputEvent event, float x, float y) {
//                setScale(1.2f);
//                setZIndex(Integer.MAX_VALUE); // bring to front
//                return true;
//            }
//
//            @Override
//            public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
//                setScale(1f);
//            }
//
//            @Override
//            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
//                System.out.println("Clicked: " + card.getName());
//                return true;
//            }
//        });
//
//        addListener(new Tooltip<>(new Label(generateTooltipText(card), skin)));
//    }
//
//    private String generateTooltipText(PlayableCard card) {
//        if (card instanceof CreatureCard creature) {
//            return creature.getKeywords().stream()
//                    .map(Keyword::toString)
//                    .collect(Collectors.joining(", "));
//        }
//        return "Playable: " + card.getCardType();
//    }
//}
