"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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 _immutable = require("immutable");

var _reduxRecord = _interopRequireDefault(require("./reduxRecord"));

var _Item2 = _interopRequireDefault(require("./Item"));

var _Stimulus2 = _interopRequireDefault(require("./Stimulus"));

var _constants = require("@instructure/quiz-common/lib/constants");

var BankEntry =
/*#__PURE__*/
function (_ReduxRecord) {
  (0, _inherits2.default)(BankEntry, _ReduxRecord);

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

  (0, _createClass2.default)(BankEntry, [{
    key: "getEntry",
    value: function getEntry() {
      var _this = this;

      if (this.entry === _constants.TEMPORARY_ITEM_ID) {
        return _Item2.default.create(this.getState().getIn(['modifications', 'items', _constants.TEMPORARY_ITEM_ID]));
      }

      if (this.entry === _constants.TEMPORARY_STIMULUS_ID) {
        return _Stimulus2.default.create(this.getState().getIn(['modifications', 'stimuli', _constants.TEMPORARY_STIMULUS_ID]));
      }

      var entryCreator = {
        Item: function Item() {
          return _Item2.default.create(_this.getState().getIn(['items', _this.entry.get('id')]));
        },
        Stimulus: function Stimulus() {
          return _Stimulus2.default.create(_this.getState().getIn(['stimuli', _this.entry.get('id')]));
        }
      }[this.entryType];
      if (entryCreator) return entryCreator();
    }
  }, {
    key: "getNestedEntries",
    value: function getNestedEntries() {
      var entry = this.getEntry();
      var getNestedEntriesFunction = {
        Item: function Item() {
          return [entry];
        }
      }[this.entryType];
      if (getNestedEntriesFunction) return getNestedEntriesFunction();
    }
  }, {
    key: "getWorkingInstance",
    value: function getWorkingInstance() {
      return this.merge(this.getState().getIn(['modifications', 'bankEntries', this.id]));
    }
  }, {
    key: "isStimulus",
    get: function get() {
      return this.entryType === 'Stimulus';
    }
  }]);
  return BankEntry;
}((0, _reduxRecord.default)({
  id: '0',
  entry: (0, _immutable.Map)(),
  bankId: '0',
  archived: false,
  entryType: null,
  createdAt: null,
  updatedAt: null
}));

exports.default = BankEntry;