"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _icons = require("@wii/icons");
var _upload = _interopRequireDefault(require("../../../upload"));
var _button = _interopRequireDefault(require("../../../button"));
var _createField = _interopRequireDefault(require("../../create-field"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 上传按钮组件
 *
 * @param
 */
const ProFormUploadButton = ({
  fieldProps,
  action,
  accept,
  listType,
  title = '单击上传',
  max,
  icon = /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.UploadOutlined, {}),
  value,
  buttonProps,
  onChange,
  disabled,
  proFieldProps
}, ref) => {
  // 如果配置了 max ，并且 超过了文件列表的大小，就不展示按钮
  const showUploadButton = (max === undefined || !value || (value === null || value === void 0 ? void 0 : value.length) < max) && (proFieldProps === null || proFieldProps === void 0 ? void 0 : proFieldProps.mode) !== 'read';
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_upload.default, {
    action: action,
    accept: accept,
    ref: ref,
    name: "fileList",
    listType: listType || 'picture',
    fileList: value,
    ...fieldProps,
    onChange: info => {
      if (onChange) {
        onChange(info);
      }
      if (fieldProps !== null && fieldProps !== void 0 && fieldProps.onChange) {
        fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.onChange(info);
      }
    },
    children: showUploadButton && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_button.default, {
      disabled: disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled),
      ...buttonProps,
      children: [icon, title]
    })
  });
};
var _default = (0, _createField.default)( /*#__PURE__*/_react.default.forwardRef(ProFormUploadButton), {
  getValueFromEvent: value => value.fileList
});
exports.default = _default;