const require_nodeType = require('../types/dist/esm/nodeType.cjs');

//#region ../react-intlayer/dist/esm/@intlayer/editor-react/dist/esm/core/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs
const renameContentNodeByKeyPath = (dictionaryContent, newKey, keyPath) => {
	let currentValue = dictionaryContent;
	let parentValue = null;
	let lastKey = null;
	for (const keyObj of keyPath) {
		parentValue = currentValue;
		if (keyObj.type === require_nodeType.NodeType.Object || keyObj.type === require_nodeType.NodeType.Array) {
			lastKey = keyObj.key;
			currentValue = currentValue[keyObj.key];
		}
		if (keyObj.type === require_nodeType.NodeType.Translation || keyObj.type === require_nodeType.NodeType.Enumeration || keyObj.type === require_nodeType.NodeType.Condition) {
			lastKey = keyObj.type;
			currentValue = currentValue[keyObj.type][keyObj.key];
		}
		if (keyObj.type === require_nodeType.NodeType.Markdown || keyObj.type === require_nodeType.NodeType.ReactNode || keyObj.type === require_nodeType.NodeType.Insertion || keyObj.type === require_nodeType.NodeType.File) {
			lastKey = keyObj.type;
			currentValue = currentValue[keyObj.type];
		}
	}
	if (parentValue && lastKey !== null) if (Array.isArray(parentValue)) parentValue[lastKey] = currentValue;
	else {
		const newParentValue = {};
		for (const key of Object.keys(parentValue)) if (key === lastKey && typeof newKey !== "undefined") newParentValue[newKey] = currentValue;
		else newParentValue[key] = parentValue[key];
		Object.keys(parentValue).forEach((key) => {
			delete parentValue[key];
		});
		Object.assign(parentValue, newParentValue);
	}
	return dictionaryContent;
};

//#endregion
exports.renameContentNodeByKeyPath = renameContentNodeByKeyPath;
//# sourceMappingURL=renameContentNodeByKeyPath.cjs.map