import React__default from 'react';
import { AutoSizer, List } from 'react-virtualized';
import { debounce } from 'lodash';

class ListView extends React__default.Component {
  constructor(props) {
    super(props);
    this.forceUpdateGrid = () => {
      this.debounced && this.debounced.cancel();
      this.debounced = debounce(() => this.listRef.current.forceUpdateGrid(), 200);
      this.debounced();
    };
    // 渲染列表项
    this.rowRender = ({
      key,
      index,
      style
    }) => {
      const {
        data,
        renderItem
      } = this.props;
      const item = data[index];
      return /*#__PURE__*/React__default.createElement("div", {
        key: key,
        style: style
      }, renderItem(item, index));
    };
    this.listRef = /*#__PURE__*/React__default.createRef();
    this.debounced = null;
  }
  componentWillUnmount() {
    this.debounced && this.debounced.cancel();
    this.listRef = null;
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.data !== this.props.data && nextProps.data.length === this.props.data.length) {
      this.forceUpdateGrid();
    }
  }
  render() {
    const {
      data = [],
      rowHeight = 30,
      className = '',
      rowRenderer
    } = this.props;
    return /*#__PURE__*/React__default.createElement(AutoSizer, {
      className: `lm-c-simple-list-layout ${className}`
    }, ({
      width,
      height
    }) => /*#__PURE__*/React__default.createElement(List, {
      width: width,
      height: height,
      rowCount: data.length,
      rowHeight: rowHeight,
      rowRenderer: rowRenderer ? rowRenderer : this.rowRender,
      ref: this.listRef
    }));
  }
}

export { ListView as L };
//# sourceMappingURL=index-f41abfce.js.map
