package com.pesets.idle.scenes.ui;


import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Window;
import com.pesets.game.Player;
import com.pesets.game.PlayerStatistics;

public class StatWindow extends Window implements ClickListener {

	private Label label, label2;
	private Player player;
	private TextButton btnReset;
	
	public StatWindow(Skin skin, Player player) {
		super("Statistics", skin);
		
		this.player = player;
		label = new Label(skin);
		add(label);
		label2 = new Label(skin);
		add(label2);
		row().space(2);
		
		btnReset = new TextButton("Reset", skin);
		btnReset.setClickListener(this);
		add(btnReset).expand().right();
	}
	
	public void update()
	{
		PlayerStatistics st = PlayerStatistics.getInstance();
		float toNextLevel = (player.getMaxExperience() - player.getExperience()) /(st.expPerSecond());
		String text = String.format("Time played: %.0fh %.0fm %.0fs    \n\nIn battle: %.0fh %.0fm %.0fs (%.0f%%)    " +
				"\n\nSpend dead: %.0fh %.0fm %.0fs (%.0f%%)    \n\nTo next level: %.0fh %.0fm %.0fs",
				st.timePlayed / 3600, (st.timePlayed % 3600) / 60, st.timePlayed % 60, 
				st.timeInBattle / 3600, (st.timeInBattle % 3600) / 60, st.timeInBattle % 60, st.getBattlePrecent() * 100,
				st.timeSpendDead / 3600, (st.timeSpendDead % 3600) / 60 , st.timeSpendDead % 60, st.getDeadPrecent() * 100,
				toNextLevel / 3600, (toNextLevel % 3600) / 60, toNextLevel % 60
				);
		label.setText(text);
		text = String.format("Enemies killed: %d\n\nDamage dealt %.0f\n\nDamage by skills: %.0f (%.0f%%)\n\nExp per minute: %.0f", 
				st.enemiesKilled, st.damageDealt, st.damageBySkills, st.getSkillDmgPrecent() * 100,
				(st.expPerSecond()) * 60);
		label2.setText(text);
		pack();
	}

	@Override
	public void click(Actor actor, float x, float y) {
		PlayerStatistics.getInstance().reset();
	}
}
