import React from 'react';
import { UploadOutlined } from '@wii/icons';
import Upload from '../../../upload';
import Button from '../../../button';
import createField from '../../create-field';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
 * 上传按钮组件
 *
 * @param
 */
const ProFormUploadButton = ({
  fieldProps,
  action,
  accept,
  listType,
  title = '单击上传',
  max,
  icon = /*#__PURE__*/_jsx(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__*/_jsx(Upload, {
    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__*/_jsxs(Button, {
      disabled: disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled),
      ...buttonProps,
      children: [icon, title]
    })
  });
};
export default createField( /*#__PURE__*/React.forwardRef(ProFormUploadButton), {
  getValueFromEvent: value => value.fileList
});