"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("core-js/modules/es.symbol.description.js");
var _react = _interopRequireDefault(require("react"));
var _icons = require("@wii/icons");
var _upload = _interopRequireDefault(require("../../../upload"));
var _createField = _interopRequireDefault(require("../../create-field"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * 拖动上传组件
 *
 * @param
 */
const ProFormUploadDragger = /*#__PURE__*/_react.default.forwardRef(({
  fieldProps,
  title = '单击或拖动文件到此区域进行上传',
  icon = /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.InboxOutlined, {}),
  description = '支持单次或批量上传',
  action,
  accept,
  onChange,
  value,
  children,
  max,
  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.Dragger, {
    // @ts-ignore
    ref: ref,
    name: "files",
    action: action,
    accept: accept,
    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);
      }
    },
    style: {
      ...(fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.style),
      display: !showUploadButton ? 'none' : undefined
    },
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: "ant-upload-drag-icon",
        children: icon
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: "ant-upload-text",
        children: title
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: "ant-upload-hint",
        children: description
      }), children]
    })
  });
});
var _default = (0, _createField.default)(ProFormUploadDragger, {
  getValueFromEvent: value => value.fileList
});
exports.default = _default;