"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.store = void 0;

var _redux = require("@looker/redux");

var _map = _interopRequireDefault(require("lodash/map"));

var _settings = require("./settings");

var _lodes = require("./lodes");

var _specs = require("./specs");

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var isInitSuccessAction = action => {
  var _action$payload;

  return !!((_action$payload = action.payload) !== null && _action$payload !== void 0 && _action$payload.specs);
};

var actionSanitizer = (action, _id) => {
  if (isInitSuccessAction(action)) {
    action = _objectSpread(_objectSpread({}, action), {}, {
      payload: _objectSpread(_objectSpread({}, action.payload), {}, {
        specs: sanitizeSpecs(action.payload.specs)
      })
    });
  }

  return action;
};

var stateSanitizer = (state, _index) => {
  if (state.specs) {
    return _objectSpread(_objectSpread({}, state), {}, {
      specs: _objectSpread(_objectSpread({}, state.specs), {}, {
        specs: sanitizeSpecs(state.specs.specs)
      })
    });
  }

  return state;
};

var sanitizeSpecs = specList => (0, _map.default)(specList, spec => _objectSpread(_objectSpread({}, spec), {}, {
  api: spec.api ? '<api>' : undefined,
  specContent: spec.specContent ? '<specContent>' : undefined
}));

var devTools = process.env.NODE_ENV !== 'production' ? {
  actionSanitizer,
  stateSanitizer
} : false;
var store = (0, _redux.createStore)({
  devTools,
  preloadedState: {
    settings: _settings.defaultSettingsState,
    lodes: _lodes.defaultLodesState,
    specs: _specs.defaultSpecsState
  },
  reducer: {
    settings: _settings.settingsSlice.reducer,
    lodes: _lodes.lodesSlice.reducer,
    specs: _specs.specsSlice.reducer
  }
});
exports.store = store;
//# sourceMappingURL=store.js.map