"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FullPageBookingEngineElementEvents_1 = require("../engines/FullPageBookingEngine/FullPageBookingEngineElementEvents");
class StepManager {
    static getStepFromName(name) {
        for (const step of Object.values(this.currentSteps)) {
            if (step.getName() === name) {
                return step;
            }
        }
        return null;
    }
    static getStepIndex(name) {
        let index = 1;
        for (const step of this.getStepsAsArray()) {
            if (step.getName() === name) {
                return index;
            }
            index++;
        }
        return index;
    }
    static getFirstStep() {
        return this.getStepsAsArray()[0];
    }
    static getNextStepUrl(step) {
        const steps = this.getStepsAsArray();
        let nextStep = step.getStepUrl();
        for (const stepId in steps) {
            if (this.hasStep(steps[stepId]) && steps[stepId].getName() === step.getName() && stepId !== `${steps.length - 1}`) {
                nextStep = steps[parseInt(stepId, 10) + 1].getStepUrl();
                break;
            }
        }
        return nextStep;
    }
    static getPreviousStepUrl(step) {
        const steps = this.getStepsAsArray();
        let preStep = step.getStepUrl();
        for (const stepId in steps) {
            if (this.hasStep(steps[stepId]) && steps[stepId].getName() === step.getName() && stepId !== '0') {
                preStep = steps[parseInt(stepId, 10) - 1].getStepUrl();
                break;
            }
        }
        return preStep;
    }
    static hasStep(step) {
        const steps = this.getStepsAsArray();
        return steps.includes(step);
    }
    static addStep(priority, step) {
        this.currentSteps[priority] = step;
        FullPageBookingEngineElementEvents_1.FullPageBookingEngineElementEvents.reload();
    }
    static getSteps() {
        return Object.values(this.currentSteps);
    }
    /**
     * Returns a zero indexed array of Steps, imagine Object.values();
     */
    static getStepsAsArray() {
        return Object.values(this.currentSteps);
    }
}
StepManager.STEP_BASE = '/step/';
StepManager.currentSteps = {};
exports.default = StepManager;
//# sourceMappingURL=StepManager.js.map