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

var _Text2 = _interopRequireDefault(_Text);

var _Table = require('@instructure/ui-elements/lib/components/Table');

var _Table2 = _interopRequireDefault(_Table);

var _ScreenReaderContent = require('@instructure/ui-a11y/lib/components/ScreenReaderContent');

var _ScreenReaderContent2 = _interopRequireDefault(_ScreenReaderContent);

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

var _lib2 = _interopRequireDefault(_lib);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _ModerateTableRow = require('../ModerateTableRow');

var _ModerateTableRow2 = _interopRequireDefault(_ModerateTableRow);

var _ModerateTray = require('../../sidebar/ModerateTray');

var _ModerateTray2 = _interopRequireDefault(_ModerateTray);

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

var _Spinner2 = _interopRequireDefault(_Spinner);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

var _ResetQuiz = require('../../sidebar/ResetQuiz');

var _ResetQuiz2 = _interopRequireDefault(_ResetQuiz);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.ModerateTable__styles__emptyText {\n  display: block;\n  margin: ' + theme.emptyTextMargin + ' 0 0 0;\n}\n\n.ModerateTable__styles__page {\n  overflow: auto;\n  flex: 1;\n  background-color: ' + theme.pageBackgroundColor + ';\n}\n';
  },
  'emptyText': 'ModerateTable__styles__emptyText',
  'page': 'ModerateTable__styles__page'
};
var ModerateTable = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(ModerateTable, _Component);

  function ModerateTable() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = ModerateTable.__proto__ || Object.getPrototypeOf(ModerateTable)).call.apply(_ref, [this].concat(args))), _this), _this.onModerateButtonClick = function (data) {
      _this.props.onOpenTray(data);
      _this.props.openTray(data);
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }
  // ===========
  //   CONFIG
  // ===========

  (0, _createClass3.default)(ModerateTable, [{
    key: 'renderTableRows',


    // =============
    //   RENDERING
    // =============

    value: function renderTableRows() {
      var _this2 = this;

      var _props = this.props,
          onModerateLogClick = _props.onModerateLogClick,
          onResultsLinkClick = _props.onResultsLinkClick,
          shouldRenderModerateButton = _props.shouldRenderModerateButton;


      return this.props.tableData.map(function (rowData) {
        var id = rowData.id;


        return _react2.default.createElement(_ModerateTableRow2.default, {
          onResultsLinkClick: onResultsLinkClick,
          key: id,
          onModerateButtonClick: _this2.onModerateButtonClick,
          onModerateLogClick: onModerateLogClick,
          rowData: rowData,
          shouldRenderModerateButton: shouldRenderModerateButton
        });
      });
    }
  }, {
    key: 'renderTable',
    value: function renderTable() {
      return _react2.default.createElement(
        _Table2.default,
        {
          caption: _react2.default.createElement(
            _ScreenReaderContent2.default,
            null,
            'Moderation Table'
          )
        },
        _react2.default.createElement(
          'thead',
          null,
          _react2.default.createElement(
            'tr',
            null,
            _react2.default.createElement(
              'th',
              null,
              'Student'
            ),
            _react2.default.createElement(
              'th',
              null,
              'Attempts'
            ),
            _react2.default.createElement(
              'th',
              null,
              'Score'
            ),
            _react2.default.createElement(
              'th',
              null,
              'Time'
            ),
            _react2.default.createElement(
              'th',
              null,
              'Log'
            ),
            this.props.shouldRenderModerateButton && _react2.default.createElement(
              'th',
              null,
              _react2.default.createElement(
                _ScreenReaderContent2.default,
                null,
                'Moderate'
              )
            )
          )
        ),
        _react2.default.createElement(
          'tbody',
          null,
          this.renderTableRows()
        )
      );
    }
  }, {
    key: 'renderContent',
    value: function renderContent() {
      var _props2 = this.props,
          isFetching = _props2.isFetching,
          tableData = _props2.tableData,
          emptyMessage = _props2.emptyMessage;


      if (isFetching) return _react2.default.createElement(_Spinner2.default, null);

      if (tableData.length) return this.renderTable();

      return _react2.default.createElement(
        'span',
        { className: styles.emptyText },
        _react2.default.createElement(
          _Text2.default,
          null,
          emptyMessage
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.page },
        _react2.default.createElement(
          _ModerateTray2.default,
          { onClose: this.props.onCloseTray },
          _react2.default.createElement(_ResetQuiz2.default, null),
          this.props.children
        ),
        this.renderContent()
      );
    }
  }]);
  ModerateTable.displayName = 'ModerateTable'
  ;
  return ModerateTable;
}(_react.Component), _class2.propTypes = {
  children: _propTypes2.default.node,
  emptyMessage: _propTypes2.default.string,
  isFetching: _propTypes2.default.bool.isRequired,
  onCloseTray: _propTypes2.default.func,
  onModerateLogClick: _propTypes2.default.func.isRequired,
  onOpenTray: _propTypes2.default.func,
  onResultsLinkClick: _propTypes2.default.func,
  openTray: _propTypes2.default.func.isRequired,
  shouldRenderModerateButton: _propTypes2.default.bool,
  tableData: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    avatar: _propTypes2.default.string,
    id: _propTypes2.default.string.isRequired,
    name: _propTypes2.default.string.isRequired,
    quizSessionIds: _propTypes2.default.arrayOf(_propTypes2.default.string).isRequired,
    maxAttempts: _propTypes2.default.number
  })).isRequired
}, _class2.defaultProps = {
  emptyMessage: 'There is no moderation information to display yet.',
  onCloseTray: function onCloseTray() {},
  onOpenTray: function onOpenTray() {},
  shouldRenderModerateButton: true
}, _temp2)) || _class);
exports.default = ModerateTable;