'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _constants = require('../../../constants');

var _ElapsedTime = require('../resources/ElapsedTime');

var _ElapsedTime2 = _interopRequireDefault(_ElapsedTime);

var _ResponseEvent = require('./ResponseEvent');

var _ResponseEvent2 = _interopRequireDefault(_ResponseEvent);

var _SessionStartEvent = require('./SessionStartEvent');

var _SessionStartEvent2 = _interopRequireDefault(_SessionStartEvent);

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

var Event = (_temp = _class = function (_Component) {
  (0, _inherits3.default)(Event, _Component);

  function Event() {
    (0, _classCallCheck3.default)(this, Event);
    return (0, _possibleConstructorReturn3.default)(this, (Event.__proto__ || Object.getPrototypeOf(Event)).apply(this, arguments));
  }

  (0, _createClass3.default)(Event, [{
    key: 'renderResponseEvent',
    value: function renderResponseEvent(event) {
      var item = event.getItem();
      if (!item) {
        return null;
      } else {
        return _react2.default.createElement(_ResponseEvent2.default, { event: event, item: item });
      }
    }
  }, {
    key: 'renderPayload',
    value: function renderPayload(event) {
      switch (event.eventType) {
        case _constants.RESPONSE:
          return this.renderResponseEvent(event);
        case _constants.SESSION_STARTED_OR_RESUMED_EVENT:
          return _react2.default.createElement(_SessionStartEvent2.default, { event: event });
        default:
          return null; // unknown event
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          event = _props.event,
          startTime = _props.startTime;

      var payloadNode = this.renderPayload(event);
      if (!payloadNode) return null;

      return _react2.default.createElement(
        'tr',
        null,
        _react2.default.createElement(
          'td',
          { width: 1 },
          _react2.default.createElement(_ElapsedTime2.default, { eventTime: event.createdDate(), startTime: startTime })
        ),
        _react2.default.createElement(
          'td',
          { width: 'auto' },
          payloadNode
        )
      );
    }
  }]);
  Event.displayName = 'Event'
  ;
  return Event;
}(_react.Component), _class.propTypes = {
  event: _reactImmutableProptypes2.default.record,
  startTime: _propTypes2.default.instanceOf(Date)
}, _temp);
exports.default = Event;