"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _button = _interopRequireDefault(require("../../../button"));
var _space = _interopRequireDefault(require("../../../space"));
var _wauProvider = require("../../../wau-provider");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
/** @name 用于配置操作栏 */

/**
 * FormFooter 的组件，可以自动进行一些配置
 *
 * @param props
 */

const Submitter = props => {
  const intl = (0, _wauProvider.useIntl)();
  if (props.render === false) {
    return null;
  }
  const {
    form,
    onSubmit,
    render,
    onReset,
    searchConfig = {},
    submitButtonProps,
    resetButtonProps
  } = props;
  const submit = () => {
    form.submit();
    onSubmit === null || onSubmit === void 0 ? void 0 : onSubmit();
  };
  const reset = () => {
    form.resetFields();
    requestAnimationFrame(() => {
      onReset === null || onReset === void 0 ? void 0 : onReset();
    });
  };
  const {
    submitText = intl.getMessage('tableForm.submit', '提交'),
    resetText = intl.getMessage('tableForm.reset', '重置')
  } = searchConfig;
  /** 默认的操作的逻辑 */
  const dom = [/*#__PURE__*/(0, _react.createElement)(_button.default, {
    type: "primary",
    ...submitButtonProps,
    key: "submit",
    onClick: e => {
      var _submitButtonProps$on;
      submit();
      submitButtonProps === null || submitButtonProps === void 0 || (_submitButtonProps$on = submitButtonProps.onClick) === null || _submitButtonProps$on === void 0 ? void 0 : _submitButtonProps$on.call(submitButtonProps, e);
    }
  }, submitText), /*#__PURE__*/(0, _react.createElement)(_button.default, {
    htmlType: "reset",
    ...resetButtonProps,
    key: "reset",
    onClick: e => {
      var _resetButtonProps$onC;
      reset();
      resetButtonProps === null || resetButtonProps === void 0 || (_resetButtonProps$onC = resetButtonProps.onClick) === null || _resetButtonProps$onC === void 0 ? void 0 : _resetButtonProps$onC.call(resetButtonProps, e);
    }
  }, resetText)];
  const renderDom = render ? render({
    ...props,
    submit,
    reset
  }, dom) : dom;
  if (!renderDom) {
    return null;
  }
  if (Array.isArray(renderDom)) {
    if ((renderDom === null || renderDom === void 0 ? void 0 : renderDom.length) < 1) {
      return null;
    }
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_space.default, {
      children: renderDom
    });
  }
  return renderDom;
};
var _default = Submitter;
exports.default = _default;