package de.thdeg.greiner.superpangworld.graphics.immovable;

import de.thdeg.greiner.superpangworld.gameview.GameView;
import de.thdeg.greiner.superpangworld.graphics.base.GameObject;

/**
 * The progress bar of a level.
 */
public class LevelProgressBar extends GameObject {

    /** The progress of the level ranging from <code>0</code> to <code>100</code> */
    private int levelProgress;
    /** The top and bottom border of the progress bar */
    private final static String PROGRESS_BAR_BORDER = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";

    /**
     * Create a progress bar with default values.
     *
     * @param gameView the {@link GameView} to display the progress bar
     */
    public LevelProgressBar(GameView gameView){
        super(gameView);
        size = 3;
        width = 101;
        height = 8;
        levelProgress = 0;
        setPosition(GameView.WIDTH/2.0 - width,GameView.HEIGHT-(height*size));
    }

    /**
     * Draws the level progress bar onto the canvas of the {@link GameView}.
     */
    @Override
    public void addToCanvas(){
        String pixelArt = PROGRESS_BAR_BORDER;
        String progressBarMiddle = getProgressBarMiddle(levelProgress);
        pixelArt += progressBarMiddle.repeat(6);
        pixelArt += PROGRESS_BAR_BORDER;

        gameView.addBlockImageToCanvas(pixelArt, getPosition().x, getPosition().y,size, 0);
    }

    @Override
    public void updateStatus() {

    }

    /**
     * Set the progress of the level.
     *
     * @param levelProgress the progress
     */
    public void setLevelProgress(int levelProgress){
        this.levelProgress = levelProgress;
    }

    /**
     * Create the middle part of the level progress bar.
     *
     * @param progress the progress to display
     * @return the pixel art representing the middle part of the progress bar
     */
    private String getProgressBarMiddle(int progress){
        String progressbarMiddle = "W";
        progressbarMiddle += "B".repeat(progress)+" ".repeat(100-progress);
        progressbarMiddle += "W\n";
        return progressbarMiddle;
    }
}
