'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 _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _Heading = require('@instructure/ui-elements/lib/components/Heading');

var _Heading2 = _interopRequireDefault(_Heading);

var _Alert = require('@instructure/ui-alerts/lib/components/Alert');

var _Alert2 = _interopRequireDefault(_Alert);

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

var _lib2 = _interopRequireDefault(_lib);

var _formatMessage = require('@instructure/quiz-common/lib/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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._1p7UyYJCc1yXJeMonWkwM5 {\n  display: flex;\n  justify-content: flex-start;\n}\n\n._28xbKUJJHLVv4V36PT-Qnq {\n  margin: ' + theme.resultListInfoMargin + ';\n  display: flex;\n  flex-wrap: wrap;\n  justify-content: flex-start;\n  align-items: center;\n}\n\n._3dDGwG8AdY7buCHScXPjcn {\n  width: 100%;\n  font-size: ' + theme.resultListTitleFontSize + ';\n  margin: ' + theme.resultListTitleMargin + ' 0;\n}\n\n._2QQSrbBtio1TNoooWz5Ep9 {\n  width: 100%;\n}\n\n._2kmYrK8YVv-spm5D8dOYal {\n  padding-left: ' + theme.regradeAlertPadding + ';\n  padding-right: ' + theme.regradeAlertPadding + ';\n}\n';
  },
  'resultListHeading': '_1p7UyYJCc1yXJeMonWkwM5',
  'resultListInfo': '_28xbKUJJHLVv4V36PT-Qnq',
  'resultListTitle': '_3dDGwG8AdY7buCHScXPjcn',
  'resultListDescription': '_2QQSrbBtio1TNoooWz5Ep9',
  'regradeAlert': '_2kmYrK8YVv-spm5D8dOYal'
};
var QuizSessionResultHeader = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(QuizSessionResultHeader, _Component);

  function QuizSessionResultHeader() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = QuizSessionResultHeader.__proto__ || Object.getPrototypeOf(QuizSessionResultHeader)).call.apply(_ref, [this].concat(args))), _this), _this.renderRegradeAlert = function () {
      if (_this.props.regradedSessionItemResults && _this.props.regradedSessionItemResults.size > 0) {
        var questions = _this.props.regradedSessionItemResults.map(function (rsi) {
          return rsi.position;
        }).toJS().join(', ');
        return _react2.default.createElement(
          _Alert2.default,
          { variant: 'warning' },
          (0, _formatMessage2.default)('This assessment has been regraded. {\n              numRegradedSI, plural,\n                   =1 {Question {questions} has been affected.}\n                other {Questions {questions} have been affected.}\n              }', {
            questions: questions,
            numRegradedSI: _this.props.regradedSessionItemResults.count()
          })
        );
      }
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(QuizSessionResultHeader, [{
    key: 'studentName',
    value: function studentName() {
      return this.props.quizSession.userDisplayName();
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'div',
          { className: styles.resultListHeading },
          _react2.default.createElement(
            'div',
            { className: styles.resultListInfo },
            _react2.default.createElement(
              'div',
              { className: styles.resultListTitle },
              _react2.default.createElement(
                _Heading2.default,
                { level: 'h1' },
                (0, _formatMessage2.default)('Results')
              )
            ),
            _react2.default.createElement(
              'div',
              { className: styles.resultListDescription },
              this.props.studentDescription || this.studentName()
            )
          )
        ),
        _react2.default.createElement(
          'div',
          { className: styles.regradeAlert },
          this.renderRegradeAlert()
        )
      );
    }
  }]);
  QuizSessionResultHeader.displayName = 'QuizSessionResultHeader'
  ;
  return QuizSessionResultHeader;
}(_react.Component), _class2.propTypes = {
  quizSession: _reactImmutableProptypes2.default.record.isRequired,
  regradedSessionItemResults: _reactImmutableProptypes2.default.list,
  studentDescription: _propTypes2.default.node
}, _class2.defaultProps = {
  regradedSessionItemResults: null,
  studentDescription: null
}, _temp2)) || _class);
exports.default = QuizSessionResultHeader;