"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _collapse = _interopRequireDefault(require("@alifd/next/lib/collapse"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireDefault(require("react"));
require("./index.scss");
var _excluded = ["dataList", "itemList", "children"];
/**
 * 数据
 */

/**
 * 折叠面板项配置
 */

/**
 * 折叠面板类型
 */

var Collapse = function Collapse(_ref) {
  var dataList = _ref.dataList,
    itemList = _ref.itemList,
    children = _ref.children,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _otherProps = otherProps || {};
  var Panel = _collapse["default"].Panel;
  var renderContent = function renderContent(content) {
    if (!content) return null;
    var contentArray = content.split(',');
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "collapse-content-list"
    }, contentArray.map(function (item, index) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        key: index,
        className: "collapse-content-item"
      }, item.trim());
    }));
  };
  var renderItems = function renderItems() {
    if ((dataList === null || dataList === void 0 ? void 0 : dataList.length) > 0) {
      return dataList.map(function (item, index) {
        return /*#__PURE__*/_react["default"].createElement(Panel, {
          key: index,
          title: item.title
        }, item.content && renderContent(item.content));
      });
    }
    if ((itemList === null || itemList === void 0 ? void 0 : itemList.length) > 0) {
      return itemList.map(function (item, index) {
        return /*#__PURE__*/_react["default"].createElement(Panel, {
          key: index,
          title: item.title
        }, item.content);
      });
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_collapse["default"], _otherProps, renderItems());
};
Collapse.displayName = 'Collapse';
var _default = exports["default"] = Collapse;