package edu.drexel.tau.checkers.input;

import edu.drexel.tau.checkers.entities.IDrawable;
import edu.drexel.tau.checkers.events.IButtonFunc;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import java.util.ArrayList;

/**
 * A vertical list of buttons.
 */
public class Menu implements IDrawable {
    private ArrayList<Button> menuButtons = new ArrayList<>();

    public Menu(float x, float y, Action... actions) {
        for(Action action : actions) {
            this.menuButtons.add(new Button(action.item, x, y, action.func));
            y += Button.height + Button.padding * 2;
        }
    }

    public void update(GameContainer gc, StateBasedGame game) throws SlickException {
        menuButtons.forEach(button -> button.update(gc, game));
    }

    public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
        menuButtons.forEach(button -> button.render(gc, game, g));
    }

    public static class Action {
        private String item;
        private IButtonFunc func;

        public Action(String item, IButtonFunc func){
            this.item = item;
            this.func = func;
        }
    }
}
