'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('../../../../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.Header__styles__resultListHeading {\n  display: flex;\n  justify-content: flex-start;\n}\n\n.Header__styles__resultListInfo {\n  margin: ' + theme.resultListInfoMargin + ';\n  display: flex;\n  flex-wrap: wrap;\n  justify-content: flex-start;\n  align-items: center;\n}\n\n.Header__styles__resultListTitle {\n  width: 100%;\n  font-size: ' + theme.resultListTitleFontSize + ';\n  margin: ' + theme.resultListTitleMargin + ' 0;\n}\n\n.Header__styles__resultListDescription {\n  width: 100%;\n}\n\n.Header__styles__regradeAlert {\n  padding-left: ' + theme.regradeAlertPadding + ';\n  padding-right: ' + theme.regradeAlertPadding + ';\n}\n';
  },
  'resultListHeading': 'Header__styles__resultListHeading',
  'resultListInfo': 'Header__styles__resultListInfo',
  'resultListTitle': 'Header__styles__resultListTitle',
  'resultListDescription': 'Header__styles__resultListDescription',
  'regradeAlert': 'Header__styles__regradeAlert'
};
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 _s, _n;

        var questions = _this.props.regradedSessionItemResults.map(function (rsi) {
          return rsi.position;
        }).toJS().join(', ');
        return _react2.default.createElement(
          _Alert2.default,
          { variant: 'warning' },
          '\u062A\u0645\u062A \u0625\u0639\u0627\u062F\u0629 \u062A\u0642\u064A\u064A\u0645 \u062F\u0631\u062C\u0629 \u0647\u0630\u0627 \u0627\u0644\u062A\u0642\u064A\u064A\u0645. ' + (_s = _this.props.regradedSessionItemResults.count(), _n = +_s, _n === 1 ? '\u062A\u0623\u062B\u0631 \u0627\u0644\u0633\u0624\u0627\u0644 ' + questions + '. \u062A\u0623\u062B\u0631 ' : (' \u0633\u0624\u0627\u0644\u0627\u064B ' + questions + '.'))
        );
      }
    }, _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' },
                '\u0627\u0644\u0646\u062A\u0627\u0626\u062C'
              )
            ),
            _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;