"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _spin = require("antd/es/spin");

var _spin2 = _interopRequireDefault(_spin);

var _pagination = require("antd/es/pagination");

var _pagination2 = _interopRequireDefault(_pagination);

var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

require("antd/es/spin/style/css");

require("antd/es/pagination/style/css");

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _Comment = require("../../Comment");

var _Comment2 = _interopRequireDefault(_Comment);

var _CommentBox = require("../CommentBox");

var _CommentBox2 = _interopRequireDefault(_CommentBox);

require("./index.css");

var _constant = require("../../constant");

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

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

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

var CommentList = function (_Component) {
  _inherits(CommentList, _Component);

  function CommentList(props) {
    _classCallCheck(this, CommentList);

    var _this = _possibleConstructorReturn(this, (CommentList.__proto__ || Object.getPrototypeOf(CommentList)).call(this, props));

    _this.state = {};
    return _this;
  }

  _createClass(CommentList, [{
    key: "componentWillMount",
    value: function componentWillMount() {
      this.props.app.sGetComment({ page: this.props.app.page });
    }
  }, {
    key: "renderPagination",
    value: function renderPagination() {
      var _props$app = this.props.app,
          list = _props$app.list,
          total = _props$app.total,
          page = _props$app.page,
          pageType = _props$app.pageType,
          isNoMoreComment = _props$app.isNoMoreComment,
          sGetComment = _props$app.sGetComment,
          onPageChange = _props$app.onPageChange;

      if (pageType === "more") {
        if (!isNoMoreComment && list.length !== total) {
          return _react2.default.createElement(
            "div",
            {
              className: "comment-list-show-more",
              onClick: function onClick() {
                sGetComment({ page: page + 1 });
                onPageChange(page + 1);
              }
            },
            _react2.default.createElement(
              "span",
              null,
              "\u67E5\u770B\u66F4\u591A\u8BC4\u8BBA"
            )
          );
        } else {
          return null;
        }
      } else if (pageType === "pagination") {
        return _react2.default.createElement(
          "div",
          { className: "comment-list-pagination" },
          _react2.default.createElement(_pagination2.default, {
            pageSize: _constant.LIMIT,
            current: page,
            total: total,
            onChange: function onChange(p) {
              sGetComment({ page: p });
              onPageChange(p);
            }
          })
        );
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _props$app2 = this.props.app,
          list = _props$app2.list,
          total = _props$app2.total,
          loading = _props$app2.loading;


      var spinning = Boolean(loading.sGetComment || loading.sCommentFavor || loading.sReplyFavor);
      return _react2.default.createElement(
        "div",
        null,
        _react2.default.createElement(
          _spin2.default,
          { spinning: spinning },
          _react2.default.createElement(
            "div",
            null,
            "\u5171 ",
            total,
            " \u6761\u8BC4\u8BBA"
          ),
          list.map(function (item) {
            return _react2.default.createElement(_CommentBox2.default, { content: item, key: item.id, commentId: item.id });
          }),
          this.renderPagination()
        )
      );
    }
  }]);

  return CommentList;
}(_react.Component);

CommentList.propTypes = {};

exports.default = (0, _Comment2.default)(CommentList);
//# sourceMappingURL=index.js.map