import _Upload from "antd/es/upload";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["fileList", "matter", "action", "accept", "authorization", "tenantId", "preview", "flag", "style"];
/* eslint-disable @typescript-eslint/no-shadow */
import * as React from 'react';
import { useState, useEffect } from 'react';
import { PlusOutlined } from '@ant-design/icons/es/index';
import "./index.less";
var antUploadWall = function antUploadWall(_ref) {
  var fileList = _ref.fileList,
    matter = _ref.matter,
    action = _ref.action,
    accept = _ref.accept,
    authorization = _ref.authorization,
    tenantId = _ref.tenantId,
    preview = _ref.preview,
    flag = _ref.flag,
    style = _ref.style,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _style = style || {};
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var newstyle = JSON.stringify(_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 = useState(''),
    ID = _useState[0],
    setID = _useState[1];
  useEffect(function () {
    setID("upload_" + uuid());
  }, []);
  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
    }
  };
  var uploadButton = /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(PlusOutlined, null), /*#__PURE__*/React.createElement("div", {
    style: {
      marginTop: 8
    }
  }, "Upload"));
  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, _extends({
    listType: "picture-card",
    fileList: fileList
  }, props, {
    showUploadList: {
      showPreviewIcon: false
    }
  }, _otherProps), fileList.length >= 8 ? null : uploadButton))
  // <Upload
  //   className={flag ? "isflag" : ""}
  //   listType="picture-card"
  //   fileList={fileList}
  //   {...props}
  //   showUploadList={{ showPreviewIcon: false }}
  //   {..._otherProps}
  // >
  //   {fileList.length >= 8 ? null : uploadButton}
  // </Upload>
  ;
};

antUploadWall.displayName = 'antUploadWall';
export default antUploadWall;
export function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}