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; }

/* eslint-disable react/no-did-mount-set-state */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Animate from '../../animate';
import Icon from '../../icon';
import Button from '../../button';
import { obj } from '../../util';
var Expand = Animate.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.createElement("span", {
            className: "".concat(prefix, "timeline-item-icon")
          }, React.createElement(Icon, {
            type: icon,
            size: "small"
          }));
        } else {
          finalItemNode = React.createElement("span", {
            className: "".concat(prefix, "timeline-item-dot")
          });
        }
      }

      var itemCls = classNames((_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 = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefix, "timeline-item-folder"), true), _defineProperty(_classNames2, "".concat(prefix, "timeline-item-has-left-content"), timeLeft), _classNames2));
      var itemNodeCls = classNames((_classNames3 = {}, _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node"), true), _defineProperty(_classNames3, "".concat(prefix, "timeline-item-node-custom"), dot), _classNames3));
      var dotTailCls = classNames((_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.createElement("div", _extends({}, obj.pickOthers(TimelineItem.propTypes, others), {
        className: itemCls,
        ref: function ref(e) {
          _this2['timeline-item'] = e;
        }
      }), React.createElement("div", {
        className: "".concat(prefix, "timeline-item-left-content")
      }, React.createElement("p", {
        className: "".concat(prefix, "timeline-item-body")
      }, timeLeft)), React.createElement("div", {
        className: "".concat(prefix, "timeline-item-timeline")
      }, React.createElement("div", {
        className: "".concat(prefix, "timeline-item-tail")
      }, React.createElement("i", null)), React.createElement("div", {
        className: itemNodeCls
      }, finalItemNode)), React.createElement("div", {
        className: "".concat(prefix, "timeline-item-content")
      }, title ? React.createElement("div", {
        className: "".concat(prefix, "timeline-item-title")
      }, title) : null, time ? React.createElement("div", {
        className: "".concat(prefix, "timeline-item-time")
      }, time) : null, content ? React.createElement("div", {
        className: "".concat(prefix, "timeline-item-body")
      }, content) : null)) : null;
      return React.createElement("li", {
        tabIndex: "0"
      }, animation && folderIndex ? React.createElement(Expand, {
        animationAppear: false,
        beforeEnter: this.beforeEnter,
        beforeLeave: this.beforeEnter,
        afterEnter: this.beforeLeave
      }, timelineNode) : timelineNode, folderIndex === index ? React.createElement("div", {
        className: folderCls
      }, React.createElement("div", {
        className: dotTailCls
      }), foldShow ? React.createElement(Button, buttonProps, locale.fold, React.createElement(Icon, {
        type: "chevron-up"
      })) : React.createElement(Button, buttonProps, locale.expand, React.createElement(Icon, {
        type: "chevron-down"
      }))) : null);
    }
  }]);

  return TimelineItem;
}(Component);

_defineProperty(TimelineItem, "propTypes", {
  prefix: PropTypes.string,
  index: PropTypes.number,
  total: PropTypes.number,
  folderIndex: PropTypes.number,
  foldShow: PropTypes.bool,

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

  /**
   * 图标
   */
  icon: PropTypes.string,

  /**
   * 自定义时间轴节点
   */
  dot: PropTypes.node,

  /**
   * 格式化后的时间
   */
  time: PropTypes.node,

  /**
   * 标题
   */
  title: PropTypes.node,

  /**
   * 左侧时间
   */
  timeLeft: PropTypes.node,

  /**
   * 右侧内容
   */
  content: PropTypes.node,
  toggleFold: PropTypes.func,
  className: PropTypes.string,
  locale: PropTypes.object,

  /**
   * 动画
   */
  animation: PropTypes.bool
});

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

export default TimelineItem;