{"size": 1322, "ext": "js", "max_stars_repo_path": "common/lib/framework-form-wizard.js", "max_stars_repo_name": "uk-gov-mirror/ministryofjustice.hmpps-book-secure-move-frontend", "max_stars_repo_stars_event_min_datetime": "2020-03-06T12:56:32.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-16T10:29:56.000Z", "max_issues_repo_path": "common/lib/framework-form-wizard.js", "max_issues_repo_name": "ministryofjustice/hmpps-book-secure-move-frontend", "max_issues_repo_issues_event_min_datetime": "2019-07-04T16:43:34.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T22:06:38.000Z", "max_forks_repo_path": "common/lib/framework-form-wizard.js", "max_forks_repo_name": "uk-gov-mirror/ministryofjustice.hmpps-book-secure-move-frontend", "max_forks_repo_forks_event_min_datetime": "2020-07-28T11:05:33.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-11T06:12:38.000Z"}
{"max_stars_count": 7, "max_issues_count": 2137, "max_forks_count": 2, "avg_line_length": 30.0454545455, "max_line_length": 88, "alphanum_fraction": 0.6800302572}
const { startCase } = require('lodash')

const FrameworkSectionController = require('../controllers/framework/framework-section')
const FrameworkStepController = require('../controllers/framework/framework-step')
const wizard = require('../middleware/unique-form-wizard')

function defineFormWizard(req, res, next) {
  const { key, steps } = req.frameworkSection
  const { id: assessmentId, _framework, framework } = req.assessment
  const firstStep = Object.values(steps)[0]
  const wizardFields = _framework.questions
  const wizardSteps = {
    '/': {
      controller: FrameworkSectionController,
      reset: true,
      resetJourney: true,
      template: 'framework-section',
    },
    '/start': {
      next: firstStep.slug,
      reset: true,
      resetJourney: true,
      skip: true,
      noPost: true,
    },
    ...steps,
  }
  const wizardConfig = {
    controller: FrameworkStepController,
    entryPoint: true,
    journeyName: `${framework.name}-${assessmentId}-${key}`,
    journeyPageTitle: startCase(framework.name),
    name: `${framework.name}-${assessmentId}-${key}`,
    template: 'framework-step',
    defaultFormatters: ['trim', 'singlespaces', 'apostrophes', 'quotes'],
  }

  return wizard(wizardSteps, wizardFields, wizardConfig)(req, res, next)
}

module.exports = {
  defineFormWizard,
}
