import { h as KlevuFilterOrder } from './klevuFetch-ab326dc0.js';

var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
const defaults = {
    order: KlevuFilterOrder.Index,
    limit: 10,
};
/**
 * List filters that can affect given query
 *
 * @category Modifier
 * @param options
 * @returns
 */
function listFilters(options) {
    const params = Object.assign(Object.assign({}, defaults), options);
    const query = {
        filtersToReturn: {
            enabled: true,
            include: params.include,
            exclude: params.exclude,
            options: {
                order: params.order,
                limit: params.limit,
                mincount: params.mincount,
            },
            rangeFilterSettings: params.rangeFilterSettings,
        },
    };
    return {
        klevuModifierId: "listfilters",
        modifyAfter: (queries) => __awaiter(this, void 0, void 0, function* () {
            const copy = Array.from(queries);
            for (const q of copy) {
                const filters = Object.assign(Object.assign({}, q.filters), { filtersToReturn: query.filtersToReturn });
                q.filters = filters;
            }
            return copy;
        }),
        onResult: (result) => {
            var _a, _b;
            if (!(options === null || options === void 0 ? void 0 : options.filterManager)) {
                return result;
            }
            for (const qr of (_b = (_a = result.apiResponse) === null || _a === void 0 ? void 0 : _a.queryResults) !== null && _b !== void 0 ? _b : []) {
                if (qr.filters) {
                    options.filterManager.initFromListFilters(qr.filters);
                }
            }
            return result;
        },
    };
}

export { listFilters as l };

//# sourceMappingURL=listFilters-9dca05b9.js.map