"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _TimelineItem = _interopRequireDefault(require("./TimelineItem"));

var _spin = _interopRequireDefault(require("../spin"));

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _enum = require("../_util/enum");

var _excluded = ["prefixCls", "spinPrefixCls", "children", "pending", "pendingDot", "className", "reverse"];

var Timeline = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Timeline, _Component);

  var _super = (0, _createSuper2["default"])(Timeline);

  function Timeline() {
    (0, _classCallCheck2["default"])(this, Timeline);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Timeline, [{
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props = this.props,
          customizePrefixCls = _this$props.prefixCls,
          spinPrefixCls = _this$props.spinPrefixCls,
          children = _this$props.children,
          _this$props$pending = _this$props.pending,
          pending = _this$props$pending === void 0 ? null : _this$props$pending,
          pendingDot = _this$props.pendingDot,
          className = _this$props.className,
          reverse = _this$props.reverse,
          restProps = (0, _objectWithoutProperties2["default"])(_this$props, _excluded);
      var getPrefixCls = this.context.getPrefixCls;
      var pendingNode = typeof pending === 'boolean' ? null : pending;
      var prefixCls = getPrefixCls('timeline', customizePrefixCls);
      var classString = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-pending"), !!pending), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-reverse"), !!reverse), _classNames), className);
      var pendingItem = pending ? /*#__PURE__*/_react["default"].createElement(_TimelineItem["default"], {
        prefixCls: prefixCls,
        pending: !!pending,
        dot: pendingDot || /*#__PURE__*/_react["default"].createElement(_spin["default"], {
          prefixCls: spinPrefixCls,
          size: _enum.Size.small
        })
      }, pendingNode) : null;
      var timeLineItems = reverse ? [pendingItem].concat((0, _toConsumableArray2["default"])(_react.Children.toArray(children).reverse())) : [].concat((0, _toConsumableArray2["default"])(_react.Children.toArray(children)), [pendingItem]); // Remove falsy items

      var truthyItems = timeLineItems.filter(function (item) {
        return !!item;
      });

      var itemsCount = _react.Children.count(truthyItems);

      var lastCls = "".concat(prefixCls, "-item-last");

      var items = _react.Children.map(truthyItems, function (ele, idx) {
        return /*#__PURE__*/(0, _react.cloneElement)(ele, {
          className: (0, _classnames["default"])([ele.props.className, !reverse && !!pending ? idx === itemsCount - 2 ? lastCls : '' : idx === itemsCount - 1 ? lastCls : ''])
        });
      });

      return /*#__PURE__*/_react["default"].createElement("ul", (0, _extends2["default"])({}, restProps, {
        className: classString
      }), items);
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Timeline;
}(_react.Component);

exports["default"] = Timeline;
Timeline.displayName = 'Timeline';
Timeline.Item = _TimelineItem["default"];
//# sourceMappingURL=Timeline.js.map
