@@ -367,7 +367,7 @@ variables:
367367 <button class="wizard-btn wizard-btn-secondary" onclick="structPhase3.previousWizardStep()" ${ index === 0 ? 'disabled' : '' } >
368368 Previous
369369 </button>
370- <button class="wizard-btn" onclick="structPhase3.nextWizardStep()" ${ index === wizardSteps . length - 1 ? 'style="display:none"' : '' } >
370+ <button class="wizard-btn" onclick="structPhase3.nextWizardStep()" ${ index === wizardSteps . length - 1 ? 'style="display:none"' : '' } ${ ! step . isResult ? 'disabled style="opacity: 0.5"' : '' } >
371371 Next
372372 </button>
373373 ${ index === wizardSteps . length - 1 ? `
@@ -403,23 +403,57 @@ variables:
403403
404404 setupWizardNavigation ( ) {
405405 document . addEventListener ( 'click' , ( e ) => {
406- if ( e . target . matches ( '.wizard-option' ) ) {
407- const panel = e . target . closest ( '.wizard-panel' ) ;
406+ // Check if the clicked element is a wizard option or its child
407+ const wizardOption = e . target . closest ( '.wizard-option' ) ;
408+ if ( wizardOption ) {
409+ const panel = wizardOption . closest ( '.wizard-panel' ) ;
410+ if ( ! panel || ! panel . classList . contains ( 'active' ) ) {
411+ return ; // Only handle clicks in the active panel
412+ }
413+
414+ // Remove selection from all options in this panel
408415 panel . querySelectorAll ( '.wizard-option' ) . forEach ( opt => opt . classList . remove ( 'selected' ) ) ;
409- e . target . classList . add ( 'selected' ) ;
416+ wizardOption . classList . add ( 'selected' ) ;
410417
411418 const step = parseInt ( panel . dataset . panel ) ;
412- const value = e . target . dataset . value ;
419+ const value = wizardOption . dataset . value ;
413420 this . wizardData [ step ] = value ;
421+
422+ console . log ( `Wizard step ${ step } selected: ${ value } ` ) ; // Debug log
423+
424+ // Remove any existing error when selection is made
425+ const existingError = panel . querySelector ( '.wizard-error' ) ;
426+ if ( existingError ) {
427+ existingError . remove ( ) ;
428+ }
429+
430+ // Enable the Next button
431+ const nextBtn = panel . querySelector ( '.wizard-btn:not(.wizard-btn-secondary)' ) ;
432+ if ( nextBtn && ! nextBtn . textContent . includes ( 'Download' ) ) {
433+ nextBtn . disabled = false ;
434+ nextBtn . style . opacity = '1' ;
435+ }
414436 }
415437 } ) ;
416438 }
417439
418440 nextWizardStep ( ) {
441+ // Validate that current step has a selection
442+ if ( ! this . wizardData [ this . currentWizardStep ] ) {
443+ this . showWizardError ( 'Please make a selection before continuing.' ) ;
444+ return ;
445+ }
446+
419447 if ( this . currentWizardStep < 2 ) {
420448 this . currentWizardStep ++ ;
421449 this . updateWizardStep ( ) ;
422450
451+ // Debug: Log current step and check if panel exists
452+ console . log ( `Advanced to step ${ this . currentWizardStep } ` ) ;
453+ const activePanel = document . querySelector ( '.wizard-panel.active' ) ;
454+ console . log ( 'Active panel:' , activePanel ) ;
455+ console . log ( 'Wizard options in active panel:' , activePanel ? activePanel . querySelectorAll ( '.wizard-option' ) . length : 0 ) ;
456+
423457 if ( this . currentWizardStep === 2 ) {
424458 this . generateWizardResult ( ) ;
425459 }
@@ -433,6 +467,38 @@ variables:
433467 }
434468 }
435469
470+ showWizardError ( message ) {
471+ // Remove any existing error
472+ const existingError = document . querySelector ( '.wizard-error' ) ;
473+ if ( existingError ) {
474+ existingError . remove ( ) ;
475+ }
476+
477+ // Create and show error message
478+ const activePanel = document . querySelector ( '.wizard-panel.active' ) ;
479+ const errorDiv = document . createElement ( 'div' ) ;
480+ errorDiv . className = 'wizard-error' ;
481+ errorDiv . style . cssText = `
482+ background-color: var(--color-error);
483+ color: white;
484+ padding: var(--space-3);
485+ border-radius: var(--radius-md);
486+ margin: var(--space-4) 0;
487+ font-size: var(--text-sm);
488+ ` ;
489+ errorDiv . textContent = message ;
490+
491+ const actions = activePanel . querySelector ( '.wizard-actions' ) ;
492+ actions . parentNode . insertBefore ( errorDiv , actions ) ;
493+
494+ // Auto-hide error after 3 seconds
495+ setTimeout ( ( ) => {
496+ if ( errorDiv . parentNode ) {
497+ errorDiv . remove ( ) ;
498+ }
499+ } , 3000 ) ;
500+ }
501+
436502 updateWizardStep ( ) {
437503 // Update progress
438504 const progress = ( this . currentWizardStep / 2 ) * 100 ;
@@ -453,6 +519,21 @@ variables:
453519 panel . classList . remove ( 'active' ) ;
454520 if ( index === this . currentWizardStep ) {
455521 panel . classList . add ( 'active' ) ;
522+
523+ // Update button states for the active panel
524+ const nextBtn = panel . querySelector ( '.wizard-btn:not(.wizard-btn-secondary)' ) ;
525+ const hasSelection = this . wizardData [ index ] !== undefined ;
526+
527+ if ( nextBtn && ! nextBtn . textContent . includes ( 'Download' ) ) {
528+ nextBtn . disabled = ! hasSelection ;
529+ nextBtn . style . opacity = hasSelection ? '1' : '0.5' ;
530+ }
531+
532+ // Update Previous button
533+ const prevBtn = panel . querySelector ( '.wizard-btn-secondary' ) ;
534+ if ( prevBtn ) {
535+ prevBtn . disabled = index === 0 ;
536+ }
456537 }
457538 } ) ;
458539 }
0 commit comments