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

var _immutable = require('immutable');

var _reduxRecord = require('./reduxRecord');

var _reduxRecord2 = _interopRequireDefault(_reduxRecord);

var _constants = require('../../constants');

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _instructureValidations = require('instructure-validations');

var _validationHelpers = require('quiz-interactions/lib/util/validationHelpers');

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

var Stimulus = (_temp = _class = function (_ReduxRecord) {
  (0, _inherits3.default)(Stimulus, _ReduxRecord);

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

  (0, _createClass3.default)(Stimulus, [{
    key: 'isLoaded',
    value: function isLoaded() {
      return this.id !== '0';
    }
  }, {
    key: 'isTemporary',
    value: function isTemporary() {
      return this.id === _constants.TEMPORARY_STIMULUS_ID;
    }
  }, {
    key: 'hasModifications',
    value: function hasModifications() {
      return !(0, _immutable.is)(this.getWorkingInstance(), this);
    }
  }, {
    key: 'getWorkingInstance',
    value: function getWorkingInstance() {
      // The record created by .merge() somehow bypasses calling the constructor where
      // methods created by the `() => {` pattern get created/set. So we feed the result
      // through the constructor manually.
      return Stimulus.create(this.merge(this.getState().getIn(['modifications', 'stimuli', this.id])));
    }
  }, {
    key: 'isImmutable',
    value: function isImmutable() {
      return this.status === 'immutable';
    }
  }, {
    key: 'isStimulus',
    get: function get() {
      return true;
    }
  }]);
  return Stimulus;
}((0, _reduxRecord2.default)({
  id: '0',
  stimulusType: 'text',
  title: '',
  instructions: '',
  body: '',
  sourceUrl: '',
  status: 'mutable'
})), _class.validations = {
  title: [(0, _instructureValidations.rule)('presence', { message: (0, _validationHelpers.presenceMessage)('Titel') })],
  body: [(0, _instructureValidations.rule)('presence', { message: (0, _validationHelpers.presenceMessage)('Inneh\xE5ll') })],
  onSelf: [(0, _instructureValidations.rule)('maxContent')]
}, _temp);
exports.default = Stimulus;