"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));
require("./index.scss");
var _messageListItem = _interopRequireDefault(require("./message-list-item"));
var _childrenNodeHandle = require("../../utils/children-node-handle");
var _excluded = ["dataList", "handleDataList", "onClick", "children", "images"];
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};
  var _React$useState = _react["default"].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 || [];
  (0, _react.useEffect)(function () {
    setCurrentDataList(dataList || []);
  }, [dataList]);
  return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
    className: "message-list__panel"
  }, _otherProps), /*#__PURE__*/_react["default"].createElement("div", {
    className: "message-list__panel__tab"
  }, (0, _childrenNodeHandle.convertChildren)(children, 'tabMessage', {
    onClickHandle: handleClick
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "message-list__panel__item-list"
  }, currentDataList ? currentDataList.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement(_messageListItem["default"], (0, _extends2["default"])({
      key: index,
      onClick: onClick
    }, item, {
      image: images[index % images.length]
    }), children);
  }) : /*#__PURE__*/_react["default"].createElement("div", null, "\u6682\u65E0\u6570\u636E")));
};
MessageList.displayName = 'MessageList';
var _default = exports["default"] = MessageList;