'use strict';

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

var ErrorHandler = require('../../../../../utils/ErrorHandler/ErrorHandler.js');
var utils = require('./utils.js');
var filtersTypeEnum = require('../../../../../components/_filters/filtersTypeEnum.js');
var personalisationUtils = require('../../../../../utils/Personalisation/personalisationUtils.js');
var utils$1 = require('../../utils.js');

class ViewSyncReportController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    GET = async (req, res, next) => {
        try {
            const renderData = await utils.default.getReport({ req, res, services: this.services });
            res.render(`dpr/routes/journeys/view-report/report`, {
                layoutPath: this.layoutPath,
                ...renderData,
            });
        }
        catch (error) {
            req.body ??= {};
            req.body.title = `Report Failed`;
            req.body.errorDescription = 'We were unable to show this report for the following reason:';
            req.body.error = new ErrorHandler.ErrorHandler(error).formatError();
            next(error);
        }
    };
    saveDefaultFilterValues = async (req, res, next) => {
        try {
            personalisationUtils.default.saveDefaults(filtersTypeEnum.FiltersType.INTERACTIVE, res, req, this.services);
            res.redirect(`${req.baseUrl}?defaultsSaved=true`);
        }
        catch (error) {
            req.body = {
                title: 'Failed to save defaults',
                error: new ErrorHandler.ErrorHandler(error).formatError(),
                ...(req.body && { ...req.body }),
            };
            next(error);
        }
    };
    removeDefaultFilterValues = async (req, res, next) => {
        try {
            personalisationUtils.default.removeDefaults(filtersTypeEnum.FiltersType.INTERACTIVE, res, req, this.services);
            res.redirect(req.baseUrl);
        }
        catch (error) {
            req.body = {
                title: 'Failed to remove defaults',
                error: new ErrorHandler.ErrorHandler(error).formatError(),
                ...(req.body && { ...req.body }),
            };
            next(error);
        }
    };
    applyFilters = async (req, res, _next) => {
        await utils$1.default.applyReportInteractiveQuery(req, res, this.services, 'filters');
    };
    applyColumns = async (req, res, _next) => {
        await utils$1.default.applyReportInteractiveQuery(req, res, this.services, 'columns');
    };
}

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