"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireDefault(require("react"));

var _classnames3 = _interopRequireDefault(require("classnames"));

var _FormField2 = require("../field/FormField");

var _icon = _interopRequireDefault(require("../icon"));

var _progress = _interopRequireDefault(require("../progress"));

var _enum = require("../core/enum");

var UploadList = /*#__PURE__*/function (_FormField) {
  (0, _inherits2["default"])(UploadList, _FormField);

  var _super = (0, _createSuper2["default"])(UploadList);

  function UploadList() {
    (0, _classCallCheck2["default"])(this, UploadList);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(UploadList, [{
    key: "render",
    value: function render() {
      var prefixCls = this.prefixCls,
          _this$props = this.props,
          items = _this$props.items,
          remove = _this$props.remove,
          showPreviewImage = _this$props.showPreviewImage,
          previewImageWidth = _this$props.previewImageWidth;
      var list = items.map(function (file) {
        var _classnames2;

        var previewImg;
        var progress;
        var removeIcon;
        var progressProps = {
          value: file.percent,
          size: _enum.Size.small,
          showInfo: false
        };

        if (showPreviewImage && file.type.startsWith('image')) {
          // temporarily set img[width] to 100
          previewImg = /*#__PURE__*/_react["default"].createElement("img", {
            width: previewImageWidth,
            alt: file.filename,
            src: file.url
          });
        }

        if (file.status === 'uploading') {
          progress = /*#__PURE__*/_react["default"].createElement("div", {
            className: "".concat(prefixCls, "-item-progress")
          }, /*#__PURE__*/_react["default"].createElement(_progress["default"], (0, _extends2["default"])({}, progressProps)));
        } else {
          var rmProps = {
            className: (0, _classnames3["default"])("".concat(prefixCls, "-item-icon"), (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-item-remove"), true)),
            type: 'close',
            onClick: function onClick() {
              remove(file);
            }
          };
          removeIcon = /*#__PURE__*/_react["default"].createElement(_icon["default"], (0, _extends2["default"])({}, rmProps));
        }

        var listProps = {
          className: (0, _classnames3["default"])("".concat(prefixCls, "-item"), (_classnames2 = {}, (0, _defineProperty2["default"])(_classnames2, "".concat(prefixCls, "-item-error"), file.status === 'error'), (0, _defineProperty2["default"])(_classnames2, "".concat(prefixCls, "-item-success"), file.status === 'success'), _classnames2))
        };
        return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({}, listProps, {
          key: file.uid
        }), previewImg, /*#__PURE__*/_react["default"].createElement("span", {
          className: "".concat(prefixCls, "-item-name")
        }, file.name), progress, removeIcon);
      });
      var listWrapperCls = items.length ? "".concat(prefixCls) : "".concat(prefixCls, "-empty");
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: listWrapperCls
      }, list);
    }
  }]);
  return UploadList;
}(_FormField2.FormField);

exports["default"] = UploadList;
UploadList.displayName = 'UploadList';
UploadList.defaultProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _FormField2.FormField.defaultProps), {}, {
  suffixCls: 'upload-list',
  items: []
});
//# sourceMappingURL=UploadList.js.map
