"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
var _upload = _interopRequireDefault(require("antd/lib/upload"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _index = require("@ant-design/icons/es/index");
require("./index.less");
var _excluded = ["fileList", "matter", "action", "accept", "authorization", "tenantId", "text", "hintStyle", "flag", "style"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var antUpload = function antUpload(_ref) {
  var fileList = _ref.fileList,
    matter = _ref.matter,
    action = _ref.action,
    accept = _ref.accept,
    authorization = _ref.authorization,
    tenantId = _ref.tenantId,
    text = _ref.text,
    hintStyle = _ref.hintStyle,
    flag = _ref.flag,
    style = _ref.style,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  // _style['height'] = _style['height'] ? _style['height'] : '30px';
  // _style['width'] = _style['width'] ? _style['width'] : '300px';
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var arrObj = Object.keys(_otherProps.style);
  if (arrObj.length > 0) {
    for (var k in _otherProps.style) {
      if (k == 'paddingRight' || k == 'paddingLeft' || k == 'paddingTop' || k == 'paddingBottom' || k == 'marginRight' || k == 'marginLeft' || k == 'marginTop' || k == 'marginBottom') {
        _otherProps.style[k] = '0px';
      }
    }
  }
  var _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  (0, React.useEffect)(function () {
    setID("upload_" + uuid());
  }, []);
  (0, React.useEffect)(function () {
    ChangeSize();
  }, [ID, _otherProps]);
  var ChangeSize = function ChangeSize() {
    setTimeout(function () {
      if (ID) {
        var elemsMax = document.getElementById(ID) || document;
        newstyle = JSON.parse(newstyle);
        elemsMax.style.paddingRight = newstyle.paddingRight ? newstyle.paddingRight : 0;
        elemsMax.style.paddingLeft = newstyle.paddingLeft ? newstyle.paddingLeft : 0;
        elemsMax.style.paddingTop = newstyle.paddingTop ? newstyle.paddingTop : 0;
        elemsMax.style.paddingBottom = newstyle.paddingBottom ? newstyle.paddingBottom : 0;
        elemsMax.style.marginRight = newstyle.marginRight ? newstyle.marginRight : 0;
        elemsMax.style.marginLeft = newstyle.marginLeft ? newstyle.marginLeft : 0;
        elemsMax.style.marginTop = newstyle.marginTop ? newstyle.marginTop : 0;
        elemsMax.style.marginBottom = newstyle.marginBottom ? newstyle.marginBottom : 0;
      }
    }, 0);
  };
  var props = {
    label: "文件上传",
    name: "file",
    title: "上传文件",
    action: action,
    accept: accept,
    headers: {
      Authorization: "Bearer " + authorization,
      'TENANT-ID': tenantId
    },
    fileList: fileList
  };
  var spanStyle = {
    fontSize: hintStyle.size,
    color: hintStyle.color,
    fontWeight: hintStyle.weight
  };
  var yangshi = {};
  for (var k in style) {
    if (k !== 'width' && k !== 'height' && k !== 'lineHeight' && k !== 'flexDirection' && k !== 'paddingRight' && k !== 'paddingLeft' && k !== 'paddingTop' && k !== 'paddingBottom' && k !== 'marginRight' && k !== 'marginLeft' && k !== 'marginTop' && k !== 'marginBottom') {
      yangshi[k] = style[k];
    }
  }
  return /*#__PURE__*/React.createElement("div", {
    id: ID,
    style: {
      width: _otherProps.style.width,
      height: _otherProps.style.height,
      display: flag ? 'none' : 'inline-block'
    }
  }, /*#__PURE__*/React.createElement(_upload["default"], (0, _extends2["default"])({}, props, _otherProps), /*#__PURE__*/React.createElement(_button["default"], {
    style: (0, _extends2["default"])({}, yangshi),
    icon: /*#__PURE__*/React.createElement(_index.UploadOutlined, null)
  }, matter), /*#__PURE__*/React.createElement("span", {
    style: (0, _extends2["default"])({}, spanStyle, {
      verticalAlign: 'bottom',
      marginLeft: '10px'
    })
  }, text)));
};
antUpload.displayName = 'antUpload';
var _default = antUpload;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}