/* ===============
   PROGRESS STEPS
   =============== */

import Globals from './_globals';

export default class Progress {
	
	private currentStep: number = 0;
	private steps: number = 3;
	$progressBar: JQuery;
	$steps: JQuery;
	
	constructor(
		private globals: Globals
	) {
	
		this.$steps = this.globals.$progress.find('.export-step');
		this.$progressBar = this.globals.$progress.find('.progress-bar');
		
	}
	
	/**
	 * Set the current step to the specified index
	 *
	 * @param {number} step
	 */
	setStep(step: number) {
	
		if (step <= this.steps && step >= 0 && step !== this.currentStep) {
			
			this.currentStep = step;
			this.$steps.removeClass('completed current');
			
			for (let i = 0; i < this.currentStep; i++) {
				this.$steps.eq(i).addClass( i === step ? 'current' : 'completed');
			}
			
			this.$progressBar.css('width', `${ (step / this.steps) * 100 }%` );
			
		}
	
	}
	
	/**
	 * Increase the current step
	 */
	increaseStep() {
		this.setStep( this.currentStep + 1 );
	}
	
	/**
	 * Decrease the current step
	 */
	decreaseStep() {
		this.setStep( this.currentStep - 1 );
	}
	
}