'use strict';

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

var localsHelper = require('../../../../../utils/localsHelper.js');
var UserReports = require('../../../../../types/UserReports.js');

class LoadReportController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    GET = async (req, res, next) => {
        try {
            const { token } = localsHelper.default.getValues(res);
            const { reportId, id, type } = req.params;
            const { dataProductDefinitionsPath } = req.query;
            const definitionSummary = await this.services.reportingService.getDefinitionSummary(token, reportId, dataProductDefinitionsPath);
            let definition;
            let classification;
            let description;
            let name;
            if (type === UserReports.ReportType.REPORT) {
                definition = await this.services.reportingService.getDefinition(token, reportId, id, dataProductDefinitionsPath);
                const { variant } = definition;
                classification = variant.classification;
                description = variant.description;
                name = variant.name;
            }
            else {
                definition = await this.services.dashboardService.getDefinition(token, reportId, id, dataProductDefinitionsPath);
                description = definition.description;
                name = definition.name;
            }
            const { name: reportName, description: reportDescription } = definitionSummary;
            const renderData = {
                reportId,
                id,
                type,
                reportName,
                name,
                classification,
                description: description || reportDescription,
            };
            res.render(`dpr/routes/journeys/view-report/sync/load-report/view`, {
                renderData,
                layoutPath: this.layoutPath,
            });
        }
        catch (error) {
            next(error);
        }
    };
}

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