'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, _temp;

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 _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var _Spinner2 = _interopRequireDefault(_Spinner);

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

var _Card2 = _interopRequireDefault(_Card);

var _ItemAnalysisRow = require('../../../../reporting/components/itemAnalysis/ItemAnalysisRow');

var _ItemAnalysisRow2 = _interopRequireDefault(_ItemAnalysisRow);

var _QuizAnalysisOverview = require('../../../../reporting/components/quizAnalysis/QuizAnalysisOverview');

var _QuizAnalysisOverview2 = _interopRequireDefault(_QuizAnalysisOverview);

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.QuizAndItemAnalysis__styles__title {\n  margin: ' + theme.titleMarginTop + ' ' + theme.titleMarginLeftRight + ' ' + theme.titleMarginBottom + ' ' + theme.titleMarginLeftRight + ';\n}\n\n.QuizAndItemAnalysis__styles__emptyText {\n  padding: ' + theme.emptyTextPadding + ';\n  font-size: ' + theme.emptyTextFontSize + ';\n  text-align: center;\n  color: ' + theme.emptyTextColor + ';\n}\n\n[dir="ltr"] .QuizAndItemAnalysis__styles__emptyText {\n  text-align: center;\n}\n\n[dir="rtl"] .QuizAndItemAnalysis__styles__emptyText {\n  text-align: center;\n}\n';
  },
  'title': 'QuizAndItemAnalysis__styles__title',
  'emptyText': 'QuizAndItemAnalysis__styles__emptyText'
};
var QuizAndItemAnalysis = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(QuizAndItemAnalysis, _Component);

  function QuizAndItemAnalysis() {
    (0, _classCallCheck3.default)(this, QuizAndItemAnalysis);
    return (0, _possibleConstructorReturn3.default)(this, (QuizAndItemAnalysis.__proto__ || Object.getPrototypeOf(QuizAndItemAnalysis)).apply(this, arguments));
  }

  (0, _createClass3.default)(QuizAndItemAnalysis, [{
    key: 'getAnalyses',
    value: function getAnalyses(activeQuizId) {
      this.props.getExistingQuiz(activeQuizId);
      this.props.getItemAnalyses(activeQuizId);
      this.props.getQuizAnalysis(activeQuizId);
    }
  }, {
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.getAnalyses(this.props.activeQuizId);
    }
  }, {
    key: 'componentWillUpdate',
    value: function componentWillUpdate(nextProps) {
      if (this.props.activeQuizId !== nextProps.activeQuizId) {
        this.getAnalyses(nextProps.activeQuizId);
      }
    }
  }, {
    key: 'renderItemAnalysisRows',
    value: function renderItemAnalysisRows() {
      var _this2 = this;

      var _props = this.props,
          quiz = _props.quiz,
          openRows = _props.openRows,
          activeQuizId = _props.activeQuizId,
          toggleItemAnalysisRowExpanded = _props.toggleItemAnalysisRowExpanded;

      var itemAnalyses = quiz.getItemAnalyses();
      if (itemAnalyses.size <= 0) {
        return;
      }

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          'div',
          { className: styles.title },
          _react2.default.createElement(
            _Heading2.default,
            { level: 'h3', as: 'h2' },
            'T\u0101tari t\u016Bemi'
          )
        ),
        itemAnalyses.toArray().map(function (itemAnalysis, i) {
          return _react2.default.createElement(_ItemAnalysisRow2.default, {
            expanded: openRows[itemAnalysis.itemId],
            itemAnalysis: itemAnalysis,
            itemId: itemAnalysis.itemId,
            key: itemAnalysis.itemId,
            position: i + 1,
            quizId: activeQuizId,
            toggleExpanded: toggleItemAnalysisRowExpanded,
            outcomesEndpoint: _this2.props.outcomesEndpoint,
            outcomesToken: _this2.props.outcomesToken
          });
        })
      );
    }
  }, {
    key: 'renderNotFound',
    value: function renderNotFound() {
      return _react2.default.createElement(
        _Card2.default,
        { className: styles.emptyText },
        'Kaore he r\u012Bpoata an\u014D'
      );
    }
  }, {
    key: 'renderContent',
    value: function renderContent() {
      var _props2 = this.props,
          quiz = _props2.quiz,
          quizAnalysisNotFound = _props2.quizAnalysisNotFound;

      if (quizAnalysisNotFound) {
        return this.renderNotFound();
      }

      var quizAnalysis = quiz.getQuizAnalysis();
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(_QuizAnalysisOverview2.default, {
          quizAnalysis: quizAnalysis,
          quizTitle: quiz.title
        }),
        quizAnalysis.isPresent() && this.renderItemAnalysisRows()
      );
    }
  }, {
    key: 'render',
    value: function render() {
      if (this.props.quiz.isLoaded()) {
        return this.renderContent();
      } else {
        return _react2.default.createElement(_Spinner2.default, null);
      }
    }
  }]);
  QuizAndItemAnalysis.displayName = 'QuizAndItemAnalysis'
  ;
  return QuizAndItemAnalysis;
}(_react.Component), _class2.propTypes = {
  activeQuizId: _propTypes2.default.string.isRequired,
  getExistingQuiz: _propTypes2.default.func.isRequired,
  getItemAnalyses: _propTypes2.default.func.isRequired,
  getQuizAnalysis: _propTypes2.default.func.isRequired,
  openRows: _propTypes2.default.objectOf(_propTypes2.default.bool),
  outcomesEndpoint: _propTypes2.default.string,
  outcomesToken: _propTypes2.default.string,
  quiz: _reactImmutableProptypes2.default.record.isRequired,
  quizAnalysisNotFound: _propTypes2.default.bool,
  toggleItemAnalysisRowExpanded: _propTypes2.default.func.isRequired
}, _class2.defaultProps = {
  openRows: {},
  outcomesEndpoint: null,
  outcomesToken: null,
  quizAnalysisNotFound: false
}, _temp)) || _class);
exports.default = QuizAndItemAnalysis;