import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { store } from '../store';
export var types = {
  SYNC_APP_STATE: 'SYNC_APP_STATE'
};
export var reducer = function reducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var action = arguments.length > 1 ? arguments[1] : undefined;

  var newState = _objectSpread({}, 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;
};
export var syncAppState = function syncAppState(_ref) {
  var _ref2 = _slicedToArray(_ref, 2),
      key = _ref2[0],
      value = _ref2[1];

  store.dispatch({
    type: types.SYNC_APP_STATE,
    payload: {
      key: key,
      value: value
    }
  });
};