import "antd/es/drawer/style";
import _Drawer from "antd/es/drawer";
import "antd/es/button/style";
import _Button from "antd/es/button";
import React, { Fragment, useRef } from 'react';
import { withTheme } from '@rjsf/core'; // @ts-ignore

import { Theme as AntDTheme } from '@rjsf/antd';
var PluginForm = withTheme(AntDTheme);

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 = useRef(null);
  return /*#__PURE__*/React.createElement(_Drawer, {
    title: "\u914D\u7F6E ".concat(name, " \u63D2\u4EF6"),
    width: 500,
    visible: Boolean(name),
    destroyOnClose: true,
    onClose: onClose,
    footer: !readonly && /*#__PURE__*/React.createElement("div", {
      style: {
        display: 'flex',
        justifyContent: 'space-between'
      }
    }, /*#__PURE__*/React.createElement(_Button, {
      onClick: onClose
    }, "\u53D6\u6D88"), /*#__PURE__*/React.createElement(_Button, {
      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.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.createElement(Fragment, null)));
};

export default PluginDrawer;