"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 _getPrototypeOf2 = _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 _View = _interopRequireDefault(require("@instructure/ui-layout/lib/components/View"));

var _Alert = _interopRequireDefault(require("@instructure/ui-alerts/lib/components/Alert"));

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

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

var _Bank = _interopRequireDefault(require("../../../../../../common/records/Bank"));

var _QuizEntry = _interopRequireDefault(require("../../../../../../common/records/QuizEntry"));

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

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

var _dec,
    _class,
    _class2,
    _temp,
    _default_enGB_number = Intl.NumberFormat("en-GB", { style: "decimal" }).format;

var styles = {
  componentId: 'BXWam',
  template: function template(theme) {
    return "\n\n.BXWam_cLXE{background-color:".concat(theme.quizEntryBankBackgroundColor || 'inherit', ";border:").concat(theme.quizEntryBankBorderSize || 'inherit', " dashed ").concat(theme.quizEntryBankBorderColor || 'inherit', ";cursor:pointer;margin-top:").concat(theme.quizEntryBankTopMargin || 'inherit', ";padding:").concat(theme.quizEntryBankPadding || 'inherit', "}\n\n.BXWam_dpNC,[dir=ltr] .BXWam_dpNC,[dir=rtl] .BXWam_dpNC{text-align:left}\n\n.BXWam_ekHz{margin-bottom:").concat(theme.alertWrapperMargin || 'inherit', "}");
  },
  'quizEntryBank': 'BXWam_cLXE',
  'quizEntryBankText': 'BXWam_dpNC',
  'alertWrapper': 'BXWam_ekHz'
};

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

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

  function QuizEntryBank() {
    (0, _classCallCheck2.default)(this, QuizEntryBank);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(QuizEntryBank).apply(this, arguments));
  }

  (0, _createClass2.default)(QuizEntryBank, [{
    key: "renderSampleError",
    value: function renderSampleError() {
      var _s, _n, _i, _v;

      return _react.default.createElement("div", {
        className: styles.alertWrapper
      }, _react.default.createElement(_Alert.default, {
        variant: "error"
      }, _react.default.createElement(_Text.default, null, _react.default.createElement("b", null, "Max number of bank questions exceeded! "), (_s = this.props.entry.itemEntryCount, _n = +_s, (_i = Math.floor(Math.abs(+_s)), _v = (_s + '.').split('.')[1].length, _i === 1 && _v === 0 ? "This bank contains 1 question." : "This bank contains " + _default_enGB_number(this.props.entry.itemEntryCount) + " questions.")) + " ")));
    }
  }, {
    key: "renderDeletedError",
    value: function renderDeletedError() {
      return _react.default.createElement("div", {
        className: styles.alertWrapper
      }, _react.default.createElement(_Alert.default, {
        variant: "error"
      }, _react.default.createElement(_Text.default, null, "Item bank no longer exists!")));
    }
  }, {
    key: "renderErrors",
    value: function renderErrors() {
      var _this$props = this.props,
          entry = _this$props.entry,
          quizEntry = _this$props.quizEntry;

      if (entry.archived) {
        return this.renderDeletedError();
      }

      if (quizEntry.selection === 'rand' && quizEntry.sampleNum > entry.itemEntryCount) {
        return this.renderSampleError();
      }
    }
  }, {
    key: "renderContent",
    value: function renderContent() {
      var _s2, _n2, _i2, _v2, _s3, _n3, _i3, _v3;

      var sampleNum = this.props.quizEntry.sampleNum;
      if (!sampleNum) sampleNum = 0;
      return _react.default.createElement("div", {
        className: styles.quizEntryBankText
      }, _react.default.createElement(_Text.default, null, (_s2 = sampleNum, _n2 = +_s2, _n2 === 0 ? " All questions pulled from bank: " : (_i2 = Math.floor(Math.abs(+_s2)), _v2 = (_s2 + '.').split('.')[1].length, _i2 === 1 && _v2 === 0 ? _default_enGB_number(sampleNum) + " question pulled randomly from bank: " : _default_enGB_number(sampleNum) + " questions pulled randomly from bank: ")) + " ", _react.default.createElement("b", null, this.props.entry.title), _ref, (_s3 = this.props.quizEntry.pointsPossible, _n3 = +_s3, (_i3 = Math.floor(Math.abs(+_s3)), _v3 = (_s3 + '.').split('.')[1].length, _i3 === 1 && _v3 === 0 ? _default_enGB_number(this.props.quizEntry.pointsPossible) + " point per question " : _default_enGB_number(this.props.quizEntry.pointsPossible) + " points per question "))));
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        className: styles.quizEntryBank
      }, _react.default.createElement(_View.default, {
        size: "medium",
        textAlign: "center",
        margin: "large auto",
        padding: "small"
      }, this.renderErrors(), this.renderContent()));
    }
  }]);
  QuizEntryBank.displayName = "QuizEntryBank";
  return QuizEntryBank;
}(_react.Component), _class2.propTypes = {
  entry: _propTypes.default.instanceOf(_Bank.default).isRequired,
  quizEntry: _propTypes.default.instanceOf(_QuizEntry.default).isRequired
}, _temp)) || _class);
exports.default = QuizEntryBank;