"use strict";

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _animate = _interopRequireDefault(require("../../animate"));

var _icon = _interopRequireDefault(require("../../icon"));

var _button = _interopRequireDefault(require("../../button"));

var _util = require("../../util");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var Expand = _animate["default"].Expand;
/** Timeline.Item */

var TimelineItem =
/*#__PURE__*/
function (_Component) {
  _inherits(TimelineItem, _Component);

  function TimelineItem(props) {
    var _this;

    _classCallCheck(this, TimelineItem);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(TimelineItem).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "toggleFold", function (folderIndex) {
      _this.props.toggleFold(folderIndex);
    });

    _defineProperty(_assertThisInitialized(_this), "toggleSpread", function () {
      _this.setState({
        isSpread: !_this.state.isSpread
      });
    });

    _defineProperty(_assertThisInitialized(_this), "beforeEnter", function () {
      _this['timeline-item'].style['min-height'] = 'auto';
    });

    _defineProperty(_assertThisInitialized(_this), "beforeLeave", function () {
      _this['timeline-item'].style['min-height'] = '48px'; // timeleft 节点最小高度
    });

    _this.state = {
      isSpread: false
    };
    return _this;
  }

  _createClass(TimelineItem, [{
    key: "render",
    value: function render() {
      var _classNames,
          _classNames2,
          _classNames3,
          _classNames4,
          _this2 = this;

      var _this$props = this.props,
          prefix = _this$props.prefix,
          className = _this$props.className,
          state = _this$props.state,
          icon = _this$props.icon,
          dot = _this$props.dot,
          time = _this$props.time,
          title = _this$props.title,
          timeLeft = _this$props.timeLeft,
          content = _this$props.content,
          index = _this$props.index,
          total = _this$props.total,
          folderIndex = _this$props.folderIndex,
          foldShow = _this$props.foldShow,
          locale = _this$props.locale,
          animation = _this$props.animation,
          others = _objectWithoutProperties(_this$props, ["prefix", "className", "state", "icon", "dot", "time", "title", "timeLeft", "content", "index", "total", "folderIndex", "foldShow", "locale", "animation"]);

      var finalItemNode = dot;

      if (!finalItemNode) {
        if (icon) {
          finalItemNode = _react["default"].createElement("span", {
            className: "".concat(prefix, "timeline-item-icon")
          }, _react["default"].createElement(_icon["default"], {
            type: icon,
            size: "small"
          }));
        } else {
          finalItemNode = _react["default"].createElement("span", {
            className: "".concat(prefix, "timeline-item-dot")
          });
        }
      }

      var itemCls = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "timeline-item"), true), _defineProperty(_classNames, "".concat(prefix, "timeline-item-first"), index === 0), _defineProperty(_classNames, "".concat(prefix, "timeline-item-last"), index === total - 1), _defineProperty(_classNames, "".concat(prefix, "timeline-item-").concat(state), state), _defineProperty(_classNames, "".concat(prefix, "timeline-item-folded"), folderIndex), _defineProperty(_classNames, "".concat(prefix, "timeline-item-unfolded"), foldShow), _defineProperty(_classNames, "".concat(prefix, "timeline-item-has-left-content"), timeLeft), _defineProperty(_classNames, className, className), _classNames));
      var folderCls = (0, _classnames["default"])((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "timeline-item-folder"), true), _defineProperty(_classNames2, "".concat(prefix, "timeline-item-has-left-content"), timeLeft), _classNames2));
      var itemNodeCls = (0, _classnames["default"])((_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node"), true), _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node-custom"), dot), _classNames3));
      var dotTailCls = (0, _classnames["default"])((_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefix, "timeline-item-dot-tail"), true), _defineProperty(_classNames4, "".concat(prefix, "timeline-item-dot-tail-solid"), foldShow), _defineProperty(_classNames4, "".concat(prefix, "timeline-hide"), index === total - 1 && foldShow), _classNames4));
      var buttonProps = {
        text: true,
        size: 'small',
        type: 'primary',
        onClick: this.toggleFold.bind(this, folderIndex, total)
      };
      var timelineNode = folderIndex && foldShow || !folderIndex ? _react["default"].createElement("div", _extends({}, _util.obj.pickOthers(TimelineItem.propTypes, others), {
        className: itemCls,
        ref: function ref(e) {
          _this2['timeline-item'] = e;
        }
      }), _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-left-content")
      }, _react["default"].createElement("p", {
        className: "".concat(prefix, "timeline-item-body")
      }, timeLeft)), _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-timeline")
      }, _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-tail")
      }, _react["default"].createElement("i", null)), _react["default"].createElement("div", {
        className: itemNodeCls
      }, finalItemNode)), _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-content")
      }, title ? _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-title")
      }, title) : null, time ? _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-time")
      }, time) : null, content ? _react["default"].createElement("div", {
        className: "".concat(prefix, "timeline-item-body")
      }, content) : null)) : null;
      return _react["default"].createElement("li", {
        tabIndex: "0"
      }, animation && folderIndex ? _react["default"].createElement(Expand, {
        animationAppear: false,
        beforeEnter: this.beforeEnter,
        beforeLeave: this.beforeEnter,
        afterEnter: this.beforeLeave
      }, timelineNode) : timelineNode, folderIndex === index ? _react["default"].createElement("div", {
        className: folderCls
      }, _react["default"].createElement("div", {
        className: dotTailCls
      }), foldShow ? _react["default"].createElement(_button["default"], buttonProps, locale.fold, _react["default"].createElement(_icon["default"], {
        type: "chevron-up"
      })) : _react["default"].createElement(_button["default"], buttonProps, locale.expand, _react["default"].createElement(_icon["default"], {
        type: "chevron-down"
      }))) : null);
    }
  }]);

  return TimelineItem;
}(_react.Component);

_defineProperty(TimelineItem, "propTypes", {
  prefix: _propTypes["default"].string,
  index: _propTypes["default"].number,
  total: _propTypes["default"].number,
  folderIndex: _propTypes["default"].number,
  foldShow: _propTypes["default"].bool,

  /**
   * 节点状态
   */
  state: _propTypes["default"].oneOf(['done', 'process', 'error', 'success']),

  /**
   * 图标
   */
  icon: _propTypes["default"].string,

  /**
   * 自定义时间轴节点
   */
  dot: _propTypes["default"].node,

  /**
   * 格式化后的时间
   */
  time: _propTypes["default"].node,

  /**
   * 标题
   */
  title: _propTypes["default"].node,

  /**
   * 左侧时间
   */
  timeLeft: _propTypes["default"].node,

  /**
   * 右侧内容
   */
  content: _propTypes["default"].node,
  toggleFold: _propTypes["default"].func,
  className: _propTypes["default"].string,
  locale: _propTypes["default"].object,

  /**
   * 动画
   */
  animation: _propTypes["default"].bool
});

_defineProperty(TimelineItem, "defaultProps", {
  prefix: 'next-',
  state: 'done',
  toggleFold: function toggleFold() {},
  animation: true
});

var _default = TimelineItem;
exports["default"] = _default;