"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = _default;

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 _baseRecord = _interopRequireDefault(require("./baseRecord"));

var _reduxStore = _interopRequireDefault(require("../../reduxStore"));

var _stateHelper2 = _interopRequireDefault(require("../util/stateHelper"));

function _default(schema) {
  return (
    /*#__PURE__*/
    function (_BaseRecord) {
      (0, _inherits2.default)(ReduxRecord, _BaseRecord);

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

      (0, _createClass2.default)(ReduxRecord, [{
        key: "stateHelper",
        // =====================
        // =====================
        // REDUX & RELATIONSHIPS
        // =====================
        // =====================
        value: function stateHelper() {
          return _stateHelper2.default;
        }
      }, {
        key: "getState",
        value: function getState() {
          return _reduxStore.default.getAppState();
        }
      }, {
        key: "getRelationList",
        value: function getRelationList(relationName, relatedItemFinder) {
          return this[relationName].reduce(function (relatedItemsFromState, id) {
            var currChoice = _stateHelper2.default[relatedItemFinder](id);

            if (currChoice) {
              return relatedItemsFromState.push(currChoice);
            }

            return relatedItemsFromState;
          }, (0, _immutable.List)());
        }
      }]);
      return ReduxRecord;
    }((0, _baseRecord.default)(schema))
  );
}