import CatalogueListUtils from '../catalogue-list/utils.js';
import localsHelper from '../../../utils/localsHelper.js';

const initCatalogue = async ({ res, services, req }) => {
    const data = await CatalogueListUtils.getReportsList(res, services);
    const currentUrl = req?.originalUrl || '/';
    const { token, bookmarkingEnabled, dprUser, csrfToken } = localsHelper.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.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,
};

export { utils as default, initCatalogue };
//# sourceMappingURL=utils.js.map
