import React, { useEffect, useState } from "react";
import { Input } from "antd";
//#region src/plus/walletEditor/components/JsonEditor/index.tsx
const JsonEditor = ({ value, onChange, disabled = false, rows = 4, style }) => {
	const [textValue, setTextValue] = useState("");
	const [hasError, setHasError] = useState(false);
	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.createElement(Input.TextArea, {
		style,
		value: textValue,
		onChange: handleTextChange,
		rows,
		disabled,
		status: hasError ? "error" : void 0,
		allowClear: true
	});
};
//#endregion
export { JsonEditor as default };
