import { getCacheService } from "../helpers.js";
import { QuestionPageController } from "./QuestionPageController.js";
export class StatusPageController extends QuestionPageController {
  allowSaveAndExit = false;
  showReferenceNumber = false;
  constructor(model, pageDef) {
    super(model, pageDef);
    this.viewName = 'confirmation';
    this.showReferenceNumber = model.def.options?.showReferenceNumber ?? false;
  }
  getRelevantPath() {
    return this.getStatusPath();
  }
  makeGetRouteHandler() {
    return async (request, context, h) => {
      const {
        viewModel,
        viewName
      } = this;
      const cacheService = getCacheService(request.server);
      const confirmationState = await cacheService.getConfirmationState(request);

      // If there's no confirmation state, then
      // redirect the user back to the start of the form
      if (!confirmationState.confirmed) {
        return this.proceed(request, h, this.getStartPath());
      }
      const slug = request.params.slug;
      const {
        formsService
      } = this.model.services;
      const {
        getFormMetadata,
        getFormMetadataById
      } = formsService;
      const {
        submissionGuidance
      } = await getFormMetadata(slug);

      // Re-read form name if overriding display (for example, in a feedback form)
      const storedFormId = confirmationState.formId;
      const formName = storedFormId ? (await getFormMetadataById(storedFormId)).title : undefined;
      return h.view(viewName, {
        ...viewModel,
        submissionGuidance,
        formName,
        showReferenceNumber: this.showReferenceNumber,
        referenceNumber: confirmationState.referenceNumber
      });
    };
  }
}
//# sourceMappingURL=StatusPageController.js.map