import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["dataList", "handleDataList", "onClick", "children", "images"];
import React, { useEffect } from 'react';
import "./index.scss";
import { default as MessageListItem } from "./message-list-item";
import { convertChildren } from "../../utils/children-node-handle";
var MessageList = function MessageList(_ref) {
  var dataList = _ref.dataList,
    handleDataList = _ref.handleDataList,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    children = _ref.children,
    images = _ref.images,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _otherProps = otherProps || {};
  var _React$useState = React.useState(dataList || []),
    currentDataList = _React$useState[0],
    setCurrentDataList = _React$useState[1];
  // const [currentKey, setCurrentKey] = React.useState('all')

  // 切换数据源
  var handleClick = function handleClick(key) {
    handleDataList(key);
    // setCurrentDataList(newDataList)
    // setCurrentKey(key)
  };
  images = images || [];
  useEffect(function () {
    setCurrentDataList(dataList || []);
  }, [dataList]);
  return /*#__PURE__*/React.createElement("div", _extends({
    className: "message-list__panel"
  }, _otherProps), /*#__PURE__*/React.createElement("div", {
    className: "message-list__panel__tab"
  }, convertChildren(children, 'tabMessage', {
    onClickHandle: handleClick
  })), /*#__PURE__*/React.createElement("div", {
    className: "message-list__panel__item-list"
  }, currentDataList ? currentDataList.map(function (item, index) {
    return /*#__PURE__*/React.createElement(MessageListItem, _extends({
      key: index,
      onClick: onClick
    }, item, {
      image: images[index % images.length]
    }), children);
  }) : /*#__PURE__*/React.createElement("div", null, "\u6682\u65E0\u6570\u636E")));
};
MessageList.displayName = 'MessageList';
export default MessageList;