"use strict";

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

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

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

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

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

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

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

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

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

var _CentileDistribution = _interopRequireDefault(require("../charts/CentileDistribution"));

var _MetricsListItem = _interopRequireDefault(require("../MetricsListItem"));

var _theme = _interopRequireDefault(require("./theme"));

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'fOAfX',
  template: function template(theme) {
    return "\n\n.fOAfX_bGBk{padding:".concat(theme.rootPadding || 'inherit', "}\n\n.fOAfX_CIyo{padding-bottom:").concat(theme.metricWrapperPadding || 'inherit', "}\n\n.fOAfX_CIyo,.fOAfX_gasz{margin-top:").concat(theme.wrapperMargin || 'inherit', "}\n\n@media screen and (--tabletBreakPoint){.fOAfX_eiMu{flex-basis:33.3%}}\n\n@media screen and (--phoneBreakPoint){.fOAfX_eiMu{flex-basis:50%}}");
  },
  'root': 'fOAfX_bGBk',
  'metricWrapper': 'fOAfX_CIyo',
  'wrapper': 'fOAfX_gasz',
  'metric': 'fOAfX_eiMu'
};

var _ref =
/*#__PURE__*/
_react.default.createElement("br", null);

var _ref2 =
/*#__PURE__*/
_react.default.createElement(_Spinner.default, null);

var QuizAnalysisOverview = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(QuizAnalysisOverview, _Component);

  function QuizAnalysisOverview() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(QuizAnalysisOverview)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.renderBatchTimestamp = function () {
      if (_this.props.quizAnalysis.batchTimestamp) {
        var timestamp = Date.parse(_this.props.quizAnalysis.batchTimestamp);
        return _react.default.createElement(_Text.default, {
          color: "secondary",
          size: "x-small"
        }, _ref, _react.default.createElement("b", null, "Derni\xE8re mise \xE0 jour de donn\xE9es\xA0:"), "\xA0", _formatMessage.default.date(timestamp, 'medium'));
      }
    };

    return _this;
  }

  (0, _createClass2.default)(QuizAnalysisOverview, [{
    key: "defaulMetrics",
    value: function defaulMetrics() {
      var quizAnalysis = this.props.quizAnalysis;

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

      return _react.default.createElement(_MetricsList.default, null, _react.default.createElement(_MetricsListItem.default, {
        key: "highScore",
        label: "Bonne note",
        value: quizAnalysis.highScore(),
        className: styles.metric
      }), _react.default.createElement(_MetricsListItem.default, {
        key: "lowScore",
        label: "Note faible",
        value: quizAnalysis.lowScore(),
        className: styles.metric
      }), _react.default.createElement(_MetricsListItem.default, {
        key: "meanScore",
        label: "Score moyen",
        value: quizAnalysis.meanScore(),
        className: styles.metric
      }), _react.default.createElement(_MetricsListItem.default, {
        key: "standardDeviation",
        label: "\xC9cart-type",
        value: quizAnalysis.standardDeviation(),
        className: styles.metric
      }), _react.default.createElement(_MetricsListItem.default, {
        key: "meanElapsedTime",
        label: "Dur\xE9e moyenne",
        value: formattedElapsedTime,
        className: styles.metric
      }), _react.default.createElement(_MetricsListItem.default, {
        key: "cronbachsAlpha",
        label: "Coefficient alpha de Cronbach",
        value: quizAnalysis.cronbachsAlpha(),
        className: styles.metric
      }));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          animateDelay = _this$props.animateDelay,
          animateDuration = _this$props.animateDuration,
          quizAnalysis = _this$props.quizAnalysis,
          quizTitle = _this$props.quizTitle;
      if (!quizAnalysis.isLoaded()) return _ref2;
      var list = _react.default.Children.count(this.props.children) === 0 ? this.defaulMetrics() : _react.default.createElement(_MetricsList.default, null, this.props.children);
      return _react.default.createElement(_Card.default, {
        className: styles.root
      }, _react.default.createElement(_Heading.default, {
        level: "h4",
        as: "h2",
        className: styles.quizTitle
      }, quizTitle), _react.default.createElement("div", {
        className: styles.metricWrapper
      }, list), _react.default.createElement("div", {
        className: styles.wrapper
      }, _react.default.createElement(_CentileDistribution.default, {
        animateDelay: animateDelay,
        animateDuration: animateDuration,
        summaryDistribution: quizAnalysis.decileDistribution(),
        visualDistribution: quizAnalysis.centileDistribution()
      })), this.renderBatchTimestamp());
    }
  }]);
  QuizAnalysisOverview.displayName = "QuizAnalysisOverview";
  return QuizAnalysisOverview;
}(_react.Component), _class2.propTypes = {
  animateDelay: _propTypes.default.number,
  animateDuration: _propTypes.default.number,
  quizAnalysis: _reactImmutableProptypes.default.record.isRequired,
  quizTitle: _propTypes.default.string.isRequired,
  children: _propTypes.default.arrayOf(_propTypes.default.node)
}, _class2.defaultProps = {
  animateDelay: void 0,
  animateDuration: void 0,
  quizTitle: '',
  children: []
}, _temp)) || _class);
exports.default = QuizAnalysisOverview;