'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 _Text = require('@instructure/ui-elements/lib/components/Text');

var _Text2 = _interopRequireDefault(_Text);

var _MetricsList = require('@instructure/ui-elements/lib/components/MetricsList');

var _MetricsList2 = _interopRequireDefault(_MetricsList);

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

var _Heading2 = _interopRequireDefault(_Heading);

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

var _lib2 = _interopRequireDefault(_lib);

var _FormattedDuration = require('../../../common/components/shared/FormattedDuration');

var _FormattedDuration2 = _interopRequireDefault(_FormattedDuration);

var _formatMessage = require('../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _Card = require('../../../common/components/shared/Card');

var _Card2 = _interopRequireDefault(_Card);

var _Spinner = require('../../../common/components/shared/spinner/Spinner');

var _Spinner2 = _interopRequireDefault(_Spinner);

var _CentileDistribution = require('../charts/CentileDistribution');

var _CentileDistribution2 = _interopRequireDefault(_CentileDistribution);

var _MetricsListItem = require('../MetricsListItem');

var _MetricsListItem2 = _interopRequireDefault(_MetricsListItem);

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._2s2RPyaUNwvPjgG1o_GEy9 {\n  padding: ' + theme.rootPadding + ';\n}\n\n._2m2UwUU1FU0UPe0wO8QnCG {\n  margin-top: ' + theme.wrapperMargin + ';\n}\n\n@media screen and (--tabletBreakPoint) {\n\n._3mNHkh90FLzh9Ea5nr8IsV {\n    flex-basis: 33.3%\n}\n  }\n\n@media screen and (--phoneBreakPoint) {\n\n._3mNHkh90FLzh9Ea5nr8IsV {\n    flex-basis: 50%\n}\n  }\n';
  },
  'root': '_2s2RPyaUNwvPjgG1o_GEy9',
  'wrapper': '_2m2UwUU1FU0UPe0wO8QnCG',
  'metric': '_3mNHkh90FLzh9Ea5nr8IsV'
};

var _ref2 = _react2.default.createElement('br', null);

var _ref3 = _react2.default.createElement(_Spinner2.default, null);

var QuizAnalysisOverview = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(QuizAnalysisOverview, _Component);

  function QuizAnalysisOverview() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = QuizAnalysisOverview.__proto__ || Object.getPrototypeOf(QuizAnalysisOverview)).call.apply(_ref, [this].concat(args))), _this), _this.renderBatchTimestamp = function () {
      if (_this.props.quizAnalysis.batchTimestamp) {
        var timestamp = Date.parse(_this.props.quizAnalysis.batchTimestamp);
        return _react2.default.createElement(
          _Text2.default,
          { color: 'secondary', size: 'x-small' },
          _ref2,
          _react2.default.createElement(
            'b',
            null,
            (0, _formatMessage2.default)('Data Last Updated:')
          ),
          '\xA0',
          _formatMessage2.default.date(timestamp, 'medium')
        );
      }
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(QuizAnalysisOverview, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          quizAnalysis = _props.quizAnalysis,
          quizTitle = _props.quizTitle;


      if (!quizAnalysis.isLoaded()) return _ref3;

      var formattedElapsedTime = _react2.default.createElement(_FormattedDuration2.default, { timeLimitInSeconds: quizAnalysis.meanElapsedTime() });

      return _react2.default.createElement(
        _Card2.default,
        { className: styles.root },
        _react2.default.createElement(
          _Heading2.default,
          { level: 'h4', as: 'h2', className: styles.quizTitle },
          quizTitle
        ),
        _react2.default.createElement(
          'div',
          { className: styles.wrapper },
          _react2.default.createElement(
            _MetricsList2.default,
            null,
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('High Score'),
              value: quizAnalysis.highScore(),
              className: styles.metric
            }),
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('Low Score'),
              value: quizAnalysis.lowScore(),
              className: styles.metric
            }),
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('Mean Score'),
              value: quizAnalysis.meanScore(),
              className: styles.metric
            }),
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('Standard Deviation'),
              value: quizAnalysis.standardDeviation(),
              className: styles.metric
            }),
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('Mean Elapsed Time'),
              value: formattedElapsedTime,
              className: styles.metric
            }),
            _react2.default.createElement(_MetricsListItem2.default, {
              label: (0, _formatMessage2.default)('Cronbach\'s Alpha'),
              value: quizAnalysis.cronbachsAlpha(),
              className: styles.metric
            })
          )
        ),
        _react2.default.createElement(
          'div',
          { className: styles.wrapper },
          _react2.default.createElement(_CentileDistribution2.default, {
            summaryDistribution: quizAnalysis.decileDistribution(),
            visualDistribution: quizAnalysis.centileDistribution()
          })
        ),
        this.renderBatchTimestamp()
      );
    }
  }]);
  QuizAnalysisOverview.displayName = 'QuizAnalysisOverview'
  ;
  return QuizAnalysisOverview;
}(_react.Component), _class2.propTypes = {
  quizAnalysis: _reactImmutableProptypes2.default.record.isRequired,
  quizTitle: _propTypes2.default.string.isRequired
}, _class2.defaultProps = {
  quizTitle: ''
}, _temp2)) || _class);
exports.default = QuizAnalysisOverview;