'use strict';

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

const getValues = (res) => {
    const csrfToken = res.locals['csrfToken'] || 'csrfToken';
    const dprUser = setDprUserContext(res);
    return {
        token: dprUser.token,
        dprUser,
        ...setUserReports(res),
        ...setDpdPaths(res),
        ...setFeatures(res),
        ...setDefinitions(res),
        csrfToken,
    };
};
const setDefinitions = (res) => {
    const definitions = res.locals['definitions'] || [];
    return {
        definitions,
    };
};
const setFeatures = (res) => {
    return {
        bookmarkingEnabled: res.locals['bookmarkingEnabled'],
        downloadingEnabled: res.locals['downloadingEnabled'],
    };
};
const setUserReports = (res) => {
    const requestedReports = res.locals['requestedReports'] || [];
    const recentlyViewedReports = res.locals['recentlyViewedReports'] || [];
    const bookmarks = res.locals['bookmarks'] || [];
    return {
        requestedReports,
        recentlyViewedReports,
        bookmarks,
    };
};
const setDpdPaths = (res) => {
    const { definitionsPath, dpdPathFromQuery, dpdPathFromConfig, pathSuffix } = res.locals;
    return {
        definitionsPath,
        dpdPathFromQuery,
        dpdPathFromConfig,
        pathSuffix: pathSuffix || '',
    };
};
const setDprUserContext = (res) => {
    const { dprUser } = res.locals;
    const id = dprUser?.id;
    const token = dprUser?.token;
    const activeCaseLoadId = dprUser?.activeCaseLoadId;
    const staffId = dprUser?.staffId;
    const email = dprUser?.emailAddress || '';
    const displayName = dprUser?.displayName || '';
    return {
        id,
        token,
        activeCaseLoadId,
        staffId,
        email,
        displayName,
    };
};
const setDdpPathToReqQuery = (req, value) => {
    if (value) {
        req.query = {
            ...req.query,
            dataProductDefinitionsPath: value,
        };
    }
    return req.query;
};
const getRouteLocals = (res) => {
    const locals = res.app.locals.dprPaths;
    if (!locals) {
        throw new Error('Dpr Library Path locals not initialized');
    }
    return locals;
};
var localsHelper = {
    getValues,
    getRouteLocals,
    setDdpPathToReqQuery,
};

exports.default = localsHelper;
exports.getRouteLocals = getRouteLocals;
exports.getValues = getValues;
exports.setDdpPathToReqQuery = setDdpPathToReqQuery;
//# sourceMappingURL=localsHelper.js.map
