import React from 'react';
import Button from '../../../button';
import Space from '../../../space';
import { useIntl } from '../../../wau-provider';

/** @name 用于配置操作栏 */
import { createElement as _createElement } from "react";
import { jsx as _jsx } from "react/jsx-runtime";
/**
 * FormFooter 的组件，可以自动进行一些配置
 *
 * @param props
 */

const Submitter = props => {
  const intl = 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__*/_createElement(Button, {
    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__*/_createElement(Button, {
    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__*/_jsx(Space, {
      children: renderDom
    });
  }
  return renderDom;
};
export default Submitter;