package gui.widget;

import java.time.Instant;

import imgui.ImGui;

public class TimerRenderer {

	private final long endTime;

	public TimerRenderer(Instant startTime, long duration) {
		this.endTime = startTime.getEpochSecond() + duration;
	}

	private long getTimeRemaining() {
		long currentTime = Instant.now().getEpochSecond();
		return endTime - currentTime;
	}

	public void render() {
		long seconds = getTimeRemaining();
		long minutes = seconds / 60;
		String text = String.format("%02d:%02d", minutes, seconds % 60);
		var textSize = ImGui.calcTextSize(text);
		ImGui.setCursorPosX(ImGui.getIO().getDisplaySizeX() / 2.0f - textSize.x / 2.0f);
		ImGui.text(text);
	}

}
