import t from"../core/Plugin";import e from"../utils/classSet";import s from"./Excluded";export default class i extends t{constructor(t){super(t);this.currentStep=0;this.numSteps=0;this.opts=Object.assign({},{activeStepClass:"fv-plugins-wizard--active",onStepActive:()=>{},onStepInvalid:()=>{},onStepValid:()=>{},onValid:()=>{},stepClass:"fv-plugins-wizard--step"},t);this.prevStepHandler=this.onClickPrev.bind(this);this.nextStepHandler=this.onClickNext.bind(this)}install(){this.core.registerPlugin(i.EXCLUDED_PLUGIN,new s);const t=this.core.getFormElement();this.steps=[].slice.call(t.querySelectorAll(this.opts.stepSelector));this.numSteps=this.steps.length;this.steps.forEach(t=>{e(t,{[this.opts.stepClass]:true})});e(this.steps[0],{[this.opts.activeStepClass]:true});this.prevButton=t.querySelector(this.opts.prevButton);this.nextButton=t.querySelector(this.opts.nextButton);this.prevButton.addEventListener("click",this.prevStepHandler);this.nextButton.addEventListener("click",this.nextStepHandler)}uninstall(){this.core.deregisterPlugin(i.EXCLUDED_PLUGIN);this.prevButton.removeEventListener("click",this.prevStepHandler);this.nextButton.removeEventListener("click",this.nextStepHandler)}getCurrentStep(){return this.currentStep}goToPrevStep(){if(this.currentStep>=1){e(this.steps[this.currentStep],{[this.opts.activeStepClass]:false});this.currentStep--;e(this.steps[this.currentStep],{[this.opts.activeStepClass]:true});this.onStepActive()}}goToNextStep(){this.core.validate().then(t=>{if(t==="Valid"){const t=this.currentStep+1;if(t>=this.numSteps){this.currentStep=this.numSteps-1}else{e(this.steps[this.currentStep],{[this.opts.activeStepClass]:false});this.currentStep=t;e(this.steps[this.currentStep],{[this.opts.activeStepClass]:true})}this.onStepActive();this.onStepValid();if(t===this.numSteps){this.onValid()}}else if(t==="Invalid"){this.onStepInvalid()}})}onClickPrev(){this.goToPrevStep()}onClickNext(){this.goToNextStep()}onStepActive(){const t={numSteps:this.numSteps,step:this.currentStep};this.core.emit("plugins.wizard.step.active",t);this.opts.onStepActive(t)}onStepValid(){const t={numSteps:this.numSteps,step:this.currentStep};this.core.emit("plugins.wizard.step.valid",t);this.opts.onStepValid(t)}onStepInvalid(){const t={numSteps:this.numSteps,step:this.currentStep};this.core.emit("plugins.wizard.step.invalid",t);this.opts.onStepInvalid(t)}onValid(){const t={numSteps:this.numSteps};this.core.emit("plugins.wizard.valid",t);this.opts.onValid(t)}}i.EXCLUDED_PLUGIN="___wizardExcluded";