"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

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

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

var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

var _constants = require("@instructure/quiz-common/lib/constants");

var _ElapsedTime = _interopRequireDefault(require("../resources/ElapsedTime"));

var _ResponseEvent = _interopRequireDefault(require("./ResponseEvent"));

var _SessionStartEvent = _interopRequireDefault(require("./SessionStartEvent"));

var Event =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(Event, _Component);

  function Event() {
    (0, _classCallCheck2.default)(this, Event);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Event).apply(this, arguments));
  }

  (0, _createClass2.default)(Event, [{
    key: "renderResponseEvent",
    value: function renderResponseEvent(event) {
      var item = event.getItem();

      if (!item) {
        return null;
      } else {
        return _react.default.createElement(_ResponseEvent.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 _react.default.createElement(_SessionStartEvent.default, {
            event: event
          });

        default:
          return null;
        // unknown event
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          event = _this$props.event,
          startTime = _this$props.startTime;
      var payloadNode = this.renderPayload(event);
      if (!payloadNode) return null;
      return _react.default.createElement("tr", null, _react.default.createElement("td", {
        width: 1
      }, _react.default.createElement(_ElapsedTime.default, {
        eventTime: event.createdDate(),
        startTime: startTime
      })), _react.default.createElement("td", {
        width: "auto"
      }, payloadNode));
    }
  }]);
  Event.displayName = "Event";
  return Event;
}(_react.Component);

exports.default = Event;
Event.propTypes = {
  event: _reactImmutableProptypes.default.record,
  startTime: _propTypes.default.instanceOf(Date)
};