"use strict";

exports.__esModule = true;
exports.default = void 0;
var _babelRuntimeJsxStyleTransform = require("babel-runtime-jsx-style-transform");
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _view = _interopRequireDefault(require("../../view"));
var _icon = _interopRequireDefault(require("../../icon"));
var _progress = _interopRequireDefault(require("../../progress"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var Card = /*#__PURE__*/(0, _react.memo)(function (props) {
  var file = props.file,
    _onClick = props.onClick,
    onReUpload = props.onReUpload,
    onRemove = props.onRemove,
    _props$hasRemove = props.hasRemove,
    hasRemove = _props$hasRemove === void 0 ? true : _props$hasRemove,
    _props$progressProps = props.progressProps,
    progressProps = _props$progressProps === void 0 ? {} : _props$progressProps,
    style = props.style,
    reUpload = props.reUpload;
  var clsPrefix = props.prefix || 'mt-upload';
  return /*#__PURE__*/(0, _react.createElement)(_view.default, {
    key: file.uid,
    className: (0, _classnames.default)(clsPrefix + "-item", clsPrefix + "-item--card", clsPrefix + "-item--" + file.state),
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)(style)
  }, file.state !== 'error' && (file.imgURL ? /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: clsPrefix + "-item-preview",
    onClick: function onClick(e) {
      return _onClick && _onClick(file, e);
    },
    style: (0, _babelRuntimeJsxStyleTransform.rpx2vw4style)({
      backgroundImage: "url(" + file.imgURL + ")"
    })
  }) : /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: clsPrefix + "-item-waiting"
  }, /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    className: clsPrefix + "-item-icon",
    name: "picture"
  }))), file.state === 'uploading' && /*#__PURE__*/(0, _react.createElement)(_progress.default, _extends({
    className: clsPrefix + "-item-progress",
    percent: file.percent || 0
  }, progressProps)), file.state === 'error' && /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: clsPrefix + "-item-error",
    onClick: function onClick() {
      return onReUpload && onReUpload(file);
    }
  }, /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    className: (0, _classnames.default)(clsPrefix + "-item-icon", clsPrefix + "-item-icon--small", clsPrefix + "-item-icon--error"),
    name: "upload"
  }), reUpload), (file.state === 'done' || file.state === 'error') && hasRemove && /*#__PURE__*/(0, _react.createElement)(_view.default, {
    className: clsPrefix + "-item-remove",
    onClick: function onClick() {
      return onRemove && onRemove(file);
    }
  }, /*#__PURE__*/(0, _react.createElement)(_icon.default, {
    className: clsPrefix + "-item-remove-icon",
    name: "minus"
  })));
});
var _default = Card;
exports.default = _default;