package se.urmo.game.main;

import se.urmo.game.entities.ScorePopup;

import java.awt.Font;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;

public final class ScorePopupManager {
    private final List<ScorePopup> popups = new ArrayList<>();

    // convenience defaults
    private static final long LIFE_NS = 1_000_000_000L; // 1s
    private static final double RISE_PX = 16.0;
    private static final double worldX = GamePanel.SCREEN_WIDTH / 2.0 - 15;
    private static final double worldY = 230;

    public void spawn(String text) {
        popups.add(new ScorePopup(worldX, worldY, text, LIFE_NS, RISE_PX));
    }

    public void spawn(int score) {
        spawn(String.valueOf(score));
    }

    public void update() {
        // time-based; no per-tick math needed, just prune dead ones
        popups.removeIf(p -> !p.isAlive());
    }

    public void draw(Graphics2D g, int offsetX, int offsetY, Font font) {
        for (ScorePopup p : popups) {
            p.draw(g, offsetX, offsetY, font);
        }
    }

    public void clear() {
        popups.clear();
    }
}
