"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.types = exports.syncAppState = exports.reducer = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/objectSpread2"));
var _store = require("../store");
var types = exports.types = {
  SYNC_APP_STATE: 'SYNC_APP_STATE'
};
var reducer = exports.reducer = function reducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var action = arguments.length > 1 ? arguments[1] : undefined;
  var newState = (0, _objectSpread2["default"])({}, state);
  if (action.type === types.SYNC_APP_STATE) {
    newState[action.payload.key] = action.payload.value;
  }
  if (newState.space && newState.kapp && (newState.profile || newState.authenticated === false) && newState.layoutSize) {
    newState.ready = true;
  } else {
    newState.ready = false;
  }
  return newState;
};
var syncAppState = exports.syncAppState = function syncAppState(_ref) {
  var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
    key = _ref2[0],
    value = _ref2[1];
  _store.store.dispatch({
    type: types.SYNC_APP_STATE,
    payload: {
      key: key,
      value: value
    }
  });
};