/** Wizard drawer pattern — wire stepper to step-panel swap */

export default function setup(router) {
  const stepper = router.querySelector('#pat-wizard-stepper');
  const backBtn = router.querySelector('#pat-wizard-back');
  const nextBtn = router.querySelector('#pat-wizard-next');
  const drawer  = router.querySelector('#pat-wizard');
  if (!stepper || !backBtn || !nextBtn || !drawer) return;

  const total = 3;
  let step = 0;

  const sync = () => {
    stepper.step = step;
    for (let i = 0; i < total; i++) {
      const panel = router.querySelector(`[data-wizard-step="${i}"]`);
      if (panel) panel.hidden = i !== step;
    }
    backBtn.disabled = step === 0;
    nextBtn.text = step === total - 1 ? 'Create' : 'Next';
  };

  backBtn.addEventListener('press', () => {
    if (step > 0) { step--; sync(); }
  });

  nextBtn.addEventListener('press', () => {
    if (step < total - 1) { step++; sync(); }
    else { drawer.open = false; step = 0; sync(); }
  });

  sync();
}
