'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 _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _partial = require('lodash/partial');

var _partial2 = _interopRequireDefault(_partial);

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

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _ResultStimulus = require('../../../../../common/components/resources/sessionItemResult/ResultStimulus');

var _ResultStimulus2 = _interopRequireDefault(_ResultStimulus);

var _SessionItemResultWrapper = require('../SessionItemResultWrapper');

var _SessionItemResultWrapper2 = _interopRequireDefault(_SessionItemResultWrapper);

var _generateDisplayPositions = require('../../../../../common/util/generateDisplayPositions');

var _generateDisplayPositions2 = _interopRequireDefault(_generateDisplayPositions);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.SessionItemResultList__styles__root {\n  display: flex;\n  justify-content: center;\n  flex-direction: column;\n}\n';
  },
  'root': 'SessionItemResultList__styles__root'
};
var SessionItemResultList = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(SessionItemResultList, _Component);

  function SessionItemResultList() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, SessionItemResultList);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = SessionItemResultList.__proto__ || Object.getPrototypeOf(SessionItemResultList)).call.apply(_ref, [this].concat(args))), _this), _this.renderSessionItemResultWrapper = function (sessionItem, shouldRenderTopBorder) {
      var _this$props = _this.props,
          handleChangePoints = _this$props.handleChangePoints,
          handleChangeFeedback = _this$props.handleChangeFeedback,
          handleChangeGradeStatus = _this$props.handleChangeGradeStatus,
          quizSessionId = _this$props.quizSessionId,
          regradingIdentifier = _this$props.regradingIdentifier;

      var result = sessionItem.sessionItemResult;
      var item = sessionItem.getItem();
      return _react2.default.createElement(_SessionItemResultWrapper2.default, {
        handleChangeFeedback: handleChangeFeedback,
        handleChangeGradeStatus: (0, _partial2.default)(handleChangeGradeStatus, result.id, item.id),
        handleChangePoints: (0, _partial2.default)(handleChangePoints, result.id, item.id),
        item: item,
        key: sessionItem.id,
        quizSessionId: quizSessionId,
        isRegrading: sessionItem.id === regradingIdentifier,
        regradingKey: sessionItem.id,
        sessionItem: sessionItem,
        sessionItemResult: result,
        shouldRenderTopBorder: shouldRenderTopBorder
      });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(SessionItemResultList, [{
    key: 'renderItem',
    value: function renderItem(sessionItem) {
      if (sessionItem.stimulus) {
        return _react2.default.createElement(_ResultStimulus2.default, {
          key: sessionItem.id,
          stimulus: sessionItem.stimulusRecord,
          renderItem: this.renderSessionItemResultWrapper,
          sessionItem: sessionItem
          // This prop is necessary to rerender the child items when we enter regrading mode
          , regradingIdentifier: this.props.regradingIdentifier
        });
      }
      return this.renderSessionItemResultWrapper(sessionItem, true);
    }
  }, {
    key: 'renderItems',
    value: function renderItems() {
      var _this2 = this;

      return (0, _generateDisplayPositions2.default)(this.props.sessionItems).map(function (si) {
        return _this2.renderItem(si.record);
      });
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.root },
        this.renderItems()
      );
    }
  }]);
  SessionItemResultList.displayName = 'SessionItemResultList'
  ;
  return SessionItemResultList;
}(_react.Component), _class2.propTypes = {
  handleChangePoints: _propTypes2.default.func.isRequired,
  handleChangeFeedback: _propTypes2.default.func.isRequired,
  handleChangeGradeStatus: _propTypes2.default.func.isRequired,
  quizSessionId: _propTypes2.default.string.isRequired,
  regradingIdentifier: _propTypes2.default.string.isRequired,
  sessionItems: _reactImmutableProptypes2.default.list.isRequired
}, _temp2)) || _class);
exports.default = SessionItemResultList;