import "core-js/modules/es.symbol.description.js";
import React from 'react';
import { InboxOutlined } from '@wii/icons';
import Upload from '../../../upload';
import createField from '../../create-field';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
 * 拖动上传组件
 *
 * @param
 */
const ProFormUploadDragger = /*#__PURE__*/React.forwardRef(({
  fieldProps,
  title = '单击或拖动文件到此区域进行上传',
  icon = /*#__PURE__*/_jsx(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__*/_jsx(Upload.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__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx("p", {
        className: "ant-upload-drag-icon",
        children: icon
      }), /*#__PURE__*/_jsx("p", {
        className: "ant-upload-text",
        children: title
      }), /*#__PURE__*/_jsx("p", {
        className: "ant-upload-hint",
        children: description
      }), children]
    })
  });
});
export default createField(ProFormUploadDragger, {
  getValueFromEvent: value => value.fileList
});