const require_chunk = require('./chunk-U64pC571.js');
const require_isRuleGroup = require('./isRuleGroup-Cjk1Q2mj.js');
let immer = require("immer");

//#region src/utils/transformQuery.ts
/**
* Recursively steps through a query object ({@link index!RuleGroupType RuleGroupType} or {@link index!RuleGroupTypeIC RuleGroupTypeIC}),
* passing each {@link index!RuleType RuleType} object to a provided `ruleProcessor` function and returning a
* new query object if there were any referential changes.
*
* @module transformQuery
*/
const remapProperties = (obj, propertyMap, deleteRemappedProperties) => (0, immer.produce)(obj, (draft) => {
	for (const [k, v] of Object.entries(propertyMap)) if (v === false) delete draft[k];
	else if (!!v && k !== v && k in draft) {
		draft[v] = draft[k];
		if (deleteRemappedProperties) delete draft[k];
	}
});
function transformQuery(query, options = {}) {
	const { ruleProcessor = (r) => r, ruleGroupProcessor = (rg) => rg, propertyMap = {}, combinatorMap = {}, operatorMap = {}, omitPath = false, deleteRemappedProperties = true } = options;
	const processGroup = (rg) => ({
		...ruleGroupProcessor(remapProperties({
			...rg,
			...require_isRuleGroup.isRuleGroupType(rg) ? { combinator: combinatorMap[rg.combinator] ?? rg.combinator } : {}
		}, propertyMap, deleteRemappedProperties)),
		...propertyMap["rules"] === false ? null : { [propertyMap["rules"] ?? "rules"]: rg.rules.map((r, idx) => {
			const pathObject = omitPath ? null : { path: [...rg.path, idx] };
			if (typeof r === "string") return combinatorMap[r] ?? r;
			else if (require_isRuleGroup.isRuleGroup(r)) return processGroup({
				...r,
				...pathObject
			});
			return ruleProcessor(remapProperties({
				...r,
				...pathObject,
				..."operator" in r ? { operator: operatorMap[r.operator] ?? r.operator } : {}
			}, propertyMap, deleteRemappedProperties));
		}) }
	});
	return processGroup({
		...query,
		...omitPath ? null : { path: [] }
	});
}

//#endregion
Object.defineProperty(exports, 'transformQuery', {
  enumerable: true,
  get: function () {
    return transformQuery;
  }
});
//# sourceMappingURL=transformQuery-ClBRfnFg.js.map