'use strict';

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

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _OptClass = require('../internal/OptClass');

var _OptClass2 = _interopRequireDefault(_OptClass);

var _ActivityFeedItem = require('./ActivityFeedItem');

var _ActivityFeedItem2 = _interopRequireDefault(_ActivityFeedItem);

var _Badge = require('../Badge');

var _Badge2 = _interopRequireDefault(_Badge);

var _style = require('./style.scss');

var _style2 = _interopRequireDefault(_style);

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 ActivityFeed = function (_React$Component) {
  _inherits(ActivityFeed, _React$Component);

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

    var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(ActivityFeed).call(this, props));

    _this.state = {
      data: _this.props.data
    };

    _this.componentWillReceiveProps = function (nextProps) {
      _this.setState({ data: nextProps.data });
    };

    return _this;
  }

  _createClass(ActivityFeed, [{
    key: 'render',
    value: function render() {
      var feedClasses = (0, _OptClass2.default)(_style2.default, 'activity-feed', this.props.optClass);
      var badgeClasses = (0, _OptClass2.default)(_style2.default, 'indicator');

      var items = this.state.data.map(function (item, index) {
        return _react2.default.createElement(
          'li',
          { key: index },
          _react2.default.createElement(_Badge2.default, {
            icon: item.badge.icon,
            text: item.badge.text,
            theme: item.badge.theme,
            optClass: badgeClasses
          }),
          _react2.default.createElement(_ActivityFeedItem2.default, {
            name: item.name,
            profileUrl: item.profileUrl,
            profileUrlTarget: item.profileUrlTarget,
            title: item.title,
            actions: item.actions,
            text: item.text,
            time: item.timestamp
          })
        );
      });

      return _react2.default.createElement(
        'div',
        { className: feedClasses },
        _react2.default.createElement(
          'ul',
          null,
          items
        )
      );
    }
  }]);

  return ActivityFeed;
}(_react2.default.Component);

ActivityFeed.propTypes = {
  /**
   * The activity feed data.
   */
  data: _react2.default.PropTypes.array.isRequired,
  /**
   * Optional CSS class(es) to be used for local styles (string or array of strings)
   */
  optClass: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.array, _react2.default.PropTypes.string])
};
exports.default = ActivityFeed;