'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_svXK12_number = Intl.NumberFormat('sv-x-k12', { 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, _i, _v;

      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,
              'Max antal bankfr\xE5gor har \xF6verskridits! '
            ),
            (_s = this.props.entry.itemEntryCount, _n = +_s, (_i = Math.floor(Math.abs(+_s)), _v = (_s + '.').split('.')[1].length, _i === 1 && _v === 0 ? 'Den h\xE4r banken inneh\xE5ller 1 fr\xE5ga.' : 'Den h\xE4r banken inneh\xE5ller ' + _default_svXK12_number(this.props.entry.itemEntryCount) + ' fr\xE5gor.')) + ' '
          )
        )
      );
    }
  }, {
    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,
            'Produktbanken finns inte l\xE4ngre!'
          )
        )
      );
    }
  }, {
    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, _i2, _v2, _s3, _n3, _i3, _v3;

      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 ? ' Alla fr\xE5gor som tagits fr\xE5n banken: ' : (_i2 = Math.floor(Math.abs(+_s2)), _v2 = (_s2 + '.').split('.')[1].length, _i2 === 1 && _v2 === 0 ? _default_svXK12_number(sampleNum) + ' fr\xE5ga som tagits slumpm\xE4ssigt fr\xE5n banken: ' : _default_svXK12_number(sampleNum) + ' fr\xE5gor som tagits slumpm\xE4ssigt fr\xE5n banken: ')) + ' ',
          _react2.default.createElement(
            'b',
            null,
            this.props.entry.title
          ),
          _react2.default.createElement('br', null),
          (_s3 = this.props.quizEntry.pointsPossible, _n3 = +_s3, (_i3 = Math.floor(Math.abs(+_s3)), _v3 = (_s3 + '.').split('.')[1].length, _i3 === 1 && _v3 === 0 ? _default_svXK12_number(this.props.quizEntry.pointsPossible) + ' po\xE4ng per fr\xE5ga ' : _default_svXK12_number(this.props.quizEntry.pointsPossible) + ' po\xE4ng per fr\xE5ga '))
        )
      );
    }
  }, {
    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;