"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ResultItem = _interopRequireDefault(require("./ResultItem"));
require("./index.less");
var _lodash = require("lodash");
var _classnames = _interopRequireDefault(require("classnames"));
var _empty = _interopRequireDefault(require("antd/lib/empty"));
var _reactVirtualized = require("react-virtualized");
var _excluded = ["list", "showBorder"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
var prefixCls = 'ol-map-analysis-result-list';
var cache = new _reactVirtualized.CellMeasurerCache({
  defaultHeight: 50,
  fixedWidth: true
});
var ResultList = function ResultList(_ref) {
  var list = _ref.list,
    _ref$showBorder = _ref.showBorder,
    showBorder = _ref$showBorder === void 0 ? true : _ref$showBorder,
    props = _objectWithoutProperties(_ref, _excluded);
  var listRef = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    return function () {
      cache.clearAll();
    };
  }, []);
  (0, _react.useEffect)(function () {
    if (listRef.current) {
      list.forEach(function (_, index) {
        cache.clear(index, 0);
        listRef.current.recomputeRowHeights(index);
      });
    }
  }, [list]);
  var rowRenderer = function rowRenderer(_ref2) {
    var index = _ref2.index,
      key = _ref2.key,
      parent = _ref2.parent,
      style = _ref2.style;
    return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.CellMeasurer, {
      cache: cache,
      columnIndex: 0,
      key: key,
      parent: parent,
      rowIndex: index
    }, function (_ref3) {
      var registerChild = _ref3.registerChild;
      return (
        /*#__PURE__*/
        // 'style' attribute required to position cell (within parent List)
        _react["default"].createElement("div", {
          ref: registerChild,
          style: style
        }, /*#__PURE__*/_react["default"].createElement(_ResultItem["default"], _extends({
          info: list[index]
        }, props, {
          showBorder: showBorder
        })))
      );
    });
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(prefixCls, "-wrap"))
  }, (0, _lodash.isEmpty)(list) ? /*#__PURE__*/_react["default"].createElement(_empty["default"], null) : /*#__PURE__*/_react["default"].createElement(_reactVirtualized.AutoSizer, null, function (_ref4) {
    var height = _ref4.height,
      width = _ref4.width;
    return /*#__PURE__*/_react["default"].createElement(_reactVirtualized.List, {
      height: height,
      deferredMeasurementCache: cache,
      rowHeight: cache.rowHeight,
      rowRenderer: rowRenderer,
      rowCount: list.length,
      width: width,
      ref: listRef,
      id: props.idKey
    });
  })
  // list.map(item => (
  //     <ResultItem key={item[idKey]} info={item} {...props} showBorder={showBorder} />
  // ))
  );
};
ResultList.propTypes = {
  list: _propTypes["default"].array,
  showBorder: _propTypes["default"].bool,
  titleKey: _propTypes["default"].string,
  idKey: _propTypes["default"].string,
  getDetailContent: _propTypes["default"].func,
  getOtherContent: _propTypes["default"].func,
  onTitleClick: _propTypes["default"].func,
  onItemClick: _propTypes["default"].func
};
var _default = exports["default"] = ResultList;
//# sourceMappingURL=index.js.map
