import { initPollingView } from './utils.js';
import { ErrorHandler } from '../../../../utils/ErrorHandler/ErrorHandler.js';
import { createReportPollingHandler } from '../../../../controllers/reportPolling/createReportPollingHandler.js';
import { buildCurrentStatusView } from '../../../../components/_async/async-polling/current-status/utils.js';
import { captureDprError } from '../../../../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(this.services, (updated, resolution, _req, res) => {
            const viewModel = 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 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';
            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(error).formatError();
            next(error);
        }
    };
}

export { RequestStatusController, RequestStatusController as default };
//# sourceMappingURL=controller.js.map
