import { MonacoCode } from "../IDE/MonacoCode.mjs";
import { useEditedContent } from "@intlayer/editor-react";
import { jsx } from "react/jsx-runtime";

//#region src/components/DictionaryFieldEditor/JSONEditor.tsx
const JSONEditor = ({ dictionary, isDarkMode }) => {
	const { setEditedContent, editedContent } = useEditedContent();
	const isValidJSON = (jsonString) => {
		try {
			JSON.parse(jsonString);
			return true;
		} catch (_error) {
			return false;
		}
	};
	const displayedContent = editedContent?.[dictionary.localId]?.content ?? dictionary?.content;
	return /* @__PURE__ */ jsx(MonacoCode, {
		language: "json",
		onChange: (content) => {
			if (isValidJSON(content ?? "{}")) setEditedContent(dictionary.localId, JSON.parse(content ?? "{}"));
		},
		isDarkMode,
		children: JSON.stringify(displayedContent, null, 2)
	});
};

//#endregion
export { JSONEditor };
//# sourceMappingURL=JSONEditor.mjs.map