"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("antd/es/drawer/style");

var _drawer = _interopRequireDefault(require("antd/es/drawer"));

require("antd/es/button/style");

var _button = _interopRequireDefault(require("antd/es/button"));

var _react = _interopRequireWildcard(require("react"));

var _core = require("@rjsf/core");

var _antd = require("@rjsf/antd");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// @ts-ignore
var PluginForm = (0, _core.withTheme)(_antd.Theme);

var PluginDrawer = function PluginDrawer(_ref) {
  var name = _ref.name,
      schema = _ref.schema,
      initialData = _ref.initialData,
      readonly = _ref.readonly,
      onClose = _ref.onClose,
      onFinish = _ref.onFinish;

  if (!name) {
    return null;
  }

  var form = (0, _react.useRef)(null);
  return /*#__PURE__*/_react.default.createElement(_drawer.default, {
    title: "\u914D\u7F6E ".concat(name, " \u63D2\u4EF6"),
    width: 500,
    visible: Boolean(name),
    destroyOnClose: true,
    onClose: onClose,
    footer: !readonly && /*#__PURE__*/_react.default.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'space-between'
      }
    }, /*#__PURE__*/_react.default.createElement(_button.default, {
      onClick: onClose
    }, "\u53D6\u6D88"), /*#__PURE__*/_react.default.createElement(_button.default, {
      type: "primary",
      style: {
        marginRight: 8,
        marginLeft: 8
      },
      onClick: function onClick() {
        var _form$current;

        (_form$current = form.current) === null || _form$current === void 0 ? void 0 : _form$current.submit();
      }
    }, "\u786E\u8BA4"))
  }, /*#__PURE__*/_react.default.createElement(PluginForm, {
    schema: schema,
    liveValidate: true,
    formData: initialData,
    showErrorList: false,
    disabled: readonly // @ts-ignore
    ,
    ref: function ref(_form) {
      form.current = _form;
    },
    onSubmit: function onSubmit(_ref2) {
      var formData = _ref2.formData;
      onFinish(formData);
    }
  }, /*#__PURE__*/_react.default.createElement(_react.Fragment, null)));
};

var _default = PluginDrawer;
exports.default = _default;