import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React, { PureComponent } from "react";
import { js_beautify } from "js-beautify";
import MonacoEditor from "@alilc/lowcode-plugin-base-monaco-editor";
export var JSONSetter = /*#__PURE__*/function (_PureComponent) {
  function JSONSetter() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _PureComponent.call.apply(_PureComponent, [this].concat(args)) || this;
    _this.handleEditorChange = function (newValue) {
      if (newValue && newValue != "") {
        var _this$props$onChange, _this$props;
        var data = JSON.parse(newValue);
        (_this$props$onChange = (_this$props = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props, data);
      }
    };
    return _this;
  }
  _inheritsLoose(JSONSetter, _PureComponent);
  var _proto = JSONSetter.prototype;
  _proto.render = function render() {
    var value = this.props.value;
    return /*#__PURE__*/React.createElement("div", {
      className: "jsFunction_box"
    }, /*#__PURE__*/React.createElement(MonacoEditor, {
      value: js_beautify(value),
      language: "json",
      onChange: this.handleEditorChange
    }));
  };
  return JSONSetter;
}(PureComponent);