import React from 'react';
import Item from "./../Item";

// 照片视频预览
var List = function List(_ref) {
  var list = _ref.list,
    uploading = _ref.uploading,
    visibleCount = _ref.visibleCount,
    allowClear = _ref.allowClear,
    onChange = _ref.onChange,
    onReUpload = _ref.onReUpload,
    _onPreview = _ref.onPreview;
  // Delete
  function handleDelete(item, index) {
    var newList = list.filter(function (photo, photoIndex) {
      return photoIndex !== index;
    });
    onChange && onChange(newList, {
      action: 'delete'
    });
  }
  return /*#__PURE__*/React.createElement(React.Fragment, null, list && list.length > 0 ? list.map(function (item, index) {
    if (visibleCount && index + 1 > visibleCount) return null;
    return /*#__PURE__*/React.createElement(Item, {
      key: index,
      remainCount: visibleCount && index === visibleCount - 1 ? list.length - visibleCount : null,
      item: item,
      index: index,
      uploading: uploading,
      onDelete: typeof onChange === 'function' && allowClear ? handleDelete : null,
      onReUpload: onReUpload,
      onPreview: function onPreview(e) {
        _onPreview && _onPreview(item, index);
      }
    });
  }) : null);
};
export default List;