'use client';


import { useEditedContentActions } from "../@intlayer/editor-react/dist/esm/EditedContentContext.mjs";
import { getContent } from "../@intlayer/core/dist/esm/interpreter/getContent/getContent.mjs";
import { ContentSelectorRenderer } from "./ContentSelectorWrapper.mjs";
import { createElement } from "react";

//#region ../react-intlayer/dist/esm/editor/useEditedContentRenderer.mjs
const useEditedContentRenderer = ({ dictionaryKey, keyPath, children }) => {
	const editedContentContext = useEditedContentActions();
	if (editedContentContext) return editedContentContext.getEditedContentValue(dictionaryKey, keyPath) ?? children;
	return children;
};
const EditedContentRenderer = (props) => {
	const content = useEditedContentRenderer(props);
	if (typeof content === "object") {
		const transformedEditedContent = getContent(content, props, props.locale);
		if (typeof transformedEditedContent !== "string") {
			console.error(`Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`);
			return /* @__PURE__ */ createElement(ContentSelectorRenderer, {
				...props,
				key: props.children
			}, props.children);
		}
		return /* @__PURE__ */ createElement(ContentSelectorRenderer, {
			...props,
			key: props.children
		}, transformedEditedContent);
	}
	return /* @__PURE__ */ createElement(ContentSelectorRenderer, {
		...props,
		key: props.children
	}, content);
};

//#endregion
export { EditedContentRenderer, useEditedContentRenderer };
//# sourceMappingURL=useEditedContentRenderer.mjs.map