'use strict';

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

var utils$1 = require('../catalogue-list/utils.js');
var localsHelper = require('../../../utils/localsHelper.js');

const initCatalogue = async ({ res, services, req }) => {
    const data = await utils$1.default.getReportsList(res, services);
    const currentUrl = req?.originalUrl || '/';
    const { token, bookmarkingEnabled, dprUser, csrfToken } = localsHelper.default.getValues(res);
    const productCollections = (await services.productCollectionService.getProductCollections(token))?.map((collection) => ({
        value: collection.id,
        text: collection.name,
    }));
    if (productCollections && productCollections.length > 0) {
        productCollections.unshift({ value: 'RESET', text: 'Full catalogue' });
    }
    const selectedProductCollectionId = await services.productCollectionStoreService.getSelectedProductCollectionId(dprUser.id);
    const selectedProductCollection = selectedProductCollectionId &&
        (await services.productCollectionService.getProductCollection(token, selectedProductCollectionId));
    const { productCollectionEndpoint } = localsHelper.default.getRouteLocals(res);
    return {
        id: data.id,
        list: {
            head: data.head,
            rows: data.rows,
        },
        filters: {
            productCollectionInfo: {
                productCollections,
                formAction: productCollectionEndpoint,
                ...(selectedProductCollection && { selectedProductCollection }),
            },
            csrfToken,
            currentUrl,
            features: { bookmarkingEnabled },
        },
    };
};
var utils = {
    initCatalogue,
};

exports.default = utils;
exports.initCatalogue = initCatalogue;
//# sourceMappingURL=utils.js.map
