'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,
    _default_da_number = Intl.NumberFormat('da', { style: 'decimal' }).format;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _View = require('@instructure/ui-layout/lib/components/View');

var _View2 = _interopRequireDefault(_View);

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

var _Alert2 = _interopRequireDefault(_Alert);

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

var _Text2 = _interopRequireDefault(_Text);

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

var _lib2 = _interopRequireDefault(_lib);

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

var _Bank2 = _interopRequireDefault(_Bank);

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

var _QuizEntry2 = _interopRequireDefault(_QuizEntry);

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

var _theme2 = _interopRequireDefault(_theme);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.QuizEntryBankShow__styles__quizEntryBank {\n  background-color: ' + theme.quizEntryBankBackgroundColor + ';\n  border: ' + theme.quizEntryBankBorderSize + ' dashed ' + theme.quizEntryBankBorderColor + ';\n  cursor: pointer;\n  padding: ' + theme.quizEntryBankPadding + ';\n  margin-top: ' + theme.quizEntryBankTopMargin + ';\n}\n\n.QuizEntryBankShow__styles__quizEntryBankText {\n  text-align: left;\n}\n\n[dir="ltr"] .QuizEntryBankShow__styles__quizEntryBankText {\n  text-align: left;\n}\n\n[dir="rtl"] .QuizEntryBankShow__styles__quizEntryBankText {\n  text-align: left;\n}\n\n.QuizEntryBankShow__styles__alertWrapper {\n  margin-bottom: ' + theme.alertWrapperMargin + ';\n}\n';
  },
  'quizEntryBank': 'QuizEntryBankShow__styles__quizEntryBank',
  'quizEntryBankText': 'QuizEntryBankShow__styles__quizEntryBankText',
  'alertWrapper': 'QuizEntryBankShow__styles__alertWrapper'
};
var QuizEntryBank = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp = _class2 = function (_Component) {
  (0, _inherits3.default)(QuizEntryBank, _Component);

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

  (0, _createClass3.default)(QuizEntryBank, [{
    key: 'renderSampleError',
    value: function renderSampleError() {
      var _s, _n, _t, _i;

      return _react2.default.createElement(
        'div',
        { className: styles.alertWrapper },
        _react2.default.createElement(
          _Alert2.default,
          { variant: 'error' },
          _react2.default.createElement(
            _Text2.default,
            null,
            _react2.default.createElement(
              'b',
              null,
              'Maks. antal bank-sp\xF8rgsm\xE5l overskredet! '
            ),
            (_s = this.props.entry.itemEntryCount, _n = +_s, (_t = +('' + _s).replace(/^[^.]*.?|0+$/g, ''), _i = Math.floor(Math.abs(+_s)), _n === 1 || _t !== 0 && (_i === 0 || _i === 1) ? 'Denne bank indeholder 1 sp\xF8rgsm\xE5l.' : 'Denne bank indeholder ' + _default_da_number(this.props.entry.itemEntryCount) + ' sp\xF8rgsm\xE5l.')) + ' '
          )
        )
      );
    }
  }, {
    key: 'renderDeletedError',
    value: function renderDeletedError() {
      return _react2.default.createElement(
        'div',
        { className: styles.alertWrapper },
        _react2.default.createElement(
          _Alert2.default,
          { variant: 'error' },
          _react2.default.createElement(
            _Text2.default,
            null,
            'Elementbank eksisterer ikke l\xE6ngere!'
          )
        )
      );
    }
  }, {
    key: 'renderErrors',
    value: function renderErrors() {
      var _props = this.props,
          entry = _props.entry,
          quizEntry = _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, _t2, _i2, _s3, _n3, _t3, _i3;

      var sampleNum = this.props.quizEntry.sampleNum;
      if (!sampleNum) sampleNum = 0;
      return _react2.default.createElement(
        'div',
        { className: styles.quizEntryBankText },
        _react2.default.createElement(
          _Text2.default,
          null,
          (_s2 = sampleNum, _n2 = +_s2, _n2 === 0 ? ' Alle sp\xF8rgsm\xE5l trukket fra bank: ' : (_t2 = +('' + _s2).replace(/^[^.]*.?|0+$/g, ''), _i2 = Math.floor(Math.abs(+_s2)), _n2 === 1 || _t2 !== 0 && (_i2 === 0 || _i2 === 1) ? _default_da_number(sampleNum) + ' sp\xF8rgsm\xE5l trukket tilf\xE6ldigt fra banken: ' : _default_da_number(sampleNum) + ' sp\xF8rgsm\xE5l trukket tilf\xE6ldigt fra banken: ')) + ' ',
          _react2.default.createElement(
            'b',
            null,
            this.props.entry.title
          ),
          _react2.default.createElement('br', null),
          (_s3 = this.props.quizEntry.pointsPossible, _n3 = +_s3, (_t3 = +('' + _s3).replace(/^[^.]*.?|0+$/g, ''), _i3 = Math.floor(Math.abs(+_s3)), _n3 === 1 || _t3 !== 0 && (_i3 === 0 || _i3 === 1) ? _default_da_number(this.props.quizEntry.pointsPossible) + ' point pr. sp\xF8rgsm\xE5l ' : _default_da_number(this.props.quizEntry.pointsPossible) + ' point pr. sp\xF8rgsm\xE5l '))
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { className: styles.quizEntryBank },
        _react2.default.createElement(
          _View2.default,
          {
            size: 'medium',
            textAlign: 'center',
            margin: 'large auto',
            padding: 'small'
          },
          this.renderErrors(),
          this.renderContent()
        )
      );
    }
  }]);
  QuizEntryBank.displayName = 'QuizEntryBank'
  ;
  return QuizEntryBank;
}(_react.Component), _class2.propTypes = {
  entry: _propTypes2.default.instanceOf(_Bank2.default).isRequired,
  quizEntry: _propTypes2.default.instanceOf(_QuizEntry2.default).isRequired
}, _temp)) || _class);
exports.default = QuizEntryBank;