"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _upload = _interopRequireDefault(require("antd/lib/upload"));
var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));
var React = _interopRequireWildcard(require("react"));
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 RcImgUpload = function RcImgUpload(props) {
  var _useState = (0, React.useState)(''),
    baseURL = _useState[0],
    setBaseURL = _useState[1];
  var _useState2 = (0, React.useState)(''),
    identitytoken = _useState2[0],
    setIdentitytoken = _useState2[1];
  var onChange = props.onChange,
    disabled = props.disabled,
    uploadUrl = props.uploadUrl,
    fileName = props.fileName;
  (0, React.useEffect)(function () {
    setBaseURL(getApiPath());
    var token = localStorage.getItem('identitytoken');
    token && setIdentitytoken(token);
  }, []);
  var getApiPath = function getApiPath() {
    var origin = window.location.origin;
    if (origin.includes('localhost') || origin.includes('127.0.0.1')) {
      return 'http://120.77.47.73:8080';
    } else {
      return origin;
    }
  };
  return /*#__PURE__*/React.createElement(_upload["default"], {
    onChange: onChange,
    action: uploadUrl || baseURL + "/restcloud/rest/bpm/form/import",
    listType: "picture-card",
    headers: {
      identitytoken: identitytoken
    },
    withCredentials: true,
    name: fileName,
    disabled: disabled
  }, /*#__PURE__*/React.createElement(_icon["default"], {
    type: "add"
  }));
};
var _default = RcImgUpload;
exports["default"] = _default;