const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
//#region src/plus/walletEditor/components/JsonEditor/index.tsx
const JsonEditor = ({ value, onChange, disabled = false, rows = 4, style }) => {
	const [textValue, setTextValue] = (0, react.useState)("");
	const [hasError, setHasError] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		if (value !== void 0) try {
			setTextValue(JSON.stringify(value, null, 2));
			setHasError(false);
		} catch (_unused) {
			setTextValue("");
			setHasError(false);
		}
		else {
			setTextValue("");
			setHasError(false);
		}
	}, [value]);
	const handleTextChange = (e) => {
		const newText = e.target.value;
		setTextValue(newText);
		if (!newText.trim()) {
			setHasError(false);
			onChange === null || onChange === void 0 || onChange(void 0);
			return;
		}
		try {
			const parsedValue = JSON.parse(newText);
			setHasError(false);
			onChange === null || onChange === void 0 || onChange(parsedValue);
		} catch (_unused2) {
			setHasError(true);
		}
	};
	return /* @__PURE__ */ react.default.createElement(antd.Input.TextArea, {
		style,
		value: textValue,
		onChange: handleTextChange,
		rows,
		disabled,
		status: hasError ? "error" : void 0,
		allowClear: true
	});
};
//#endregion
exports.default = JsonEditor;
