'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var utils = require('./utils.js');
var ErrorHandler = require('../../../../utils/ErrorHandler/ErrorHandler.js');
var createReportPollingHandler = require('../../../../controllers/reportPolling/createReportPollingHandler.js');
var utils$1 = require('../../../../components/_async/async-polling/current-status/utils.js');
var captureError = require('../../../../utils/captureError.js');

class RequestStatusController {
    layoutPath;
    services;
    getCurrentStatus;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
        // Polling current status - render partial
        this.getCurrentStatus = createReportPollingHandler.createReportPollingHandler(this.services, (updated, resolution, _req, res) => {
            const viewModel = utils$1.buildCurrentStatusView(updated, resolution.newStatus, res);
            return {
                template: 'dpr/components/_async/async-polling/current-status/view.njk',
                data: { data: viewModel },
            };
        });
    }
    // Render status page
    GET = async (req, res, next) => {
        try {
            const pollingRenderData = await utils.initPollingView({
                req,
                res,
                services: this.services,
                next,
            });
            res.render(`dpr/routes/journeys/request-report/status/view`, {
                layoutPath: this.layoutPath,
                ...pollingRenderData,
            });
        }
        catch (error) {
            const message = 'Failed to retrieve report status';
            captureError.captureDprError(error, message);
            req.body ??= {};
            req.body.title = message;
            req.body.errorDescription = 'We were unable to retrieve the report status:';
            req.body.error = new ErrorHandler.ErrorHandler(error).formatError();
            next(error);
        }
    };
}

exports.RequestStatusController = RequestStatusController;
exports.default = RequestStatusController;
//# sourceMappingURL=controller.js.map
