"use strict";

var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
_Object$defineProperty(exports, "__esModule", {
  value: true
});
exports.initialState = exports.default = void 0;
exports.reducer = reducer;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
var _immutable = require("immutable");
var _widgetMessage = require("@webex/widget-message");
var _widgetMeet = require("@webex/widget-meet");
var _widgetRoster = require("@webex/widget-roster");
var _reduxModuleErrors = _interopRequireDefault(require("@webex/redux-module-errors"));
var _reduxModuleFeatures = _interopRequireDefault(require("@webex/redux-module-features"));
var _reduxModuleMercury = _interopRequireDefault(require("@webex/redux-module-mercury"));
var _reduxModuleMedia = _interopRequireDefault(require("@webex/redux-module-media"));
var _reduxModuleSpaces = _interopRequireDefault(require("@webex/redux-module-spaces"));
var _reduxModuleUsers = _interopRequireDefault(require("@webex/redux-module-users"));
var _actions = require("./actions");
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
var Status = (0, _immutable.Record)({
  activityMenuVisible: false,
  hasError: false,
  hasFetchedFeatureFlags: false,
  isFetchingFeatureFlags: false,
  isFetchingSpaceDetails: false,
  shouldReloadWidget: false
});
var Destination = (0, _immutable.Record)({
  id: null,
  type: null
});
var initialState = exports.initialState = (0, _immutable.fromJS)({
  activityTypes: [],
  destination: null,
  error: null,
  primaryActivityType: null,
  secondaryActivityType: null,
  spaceDetails: null,
  status: new Status()
});
function reducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
  var action = arguments.length > 1 ? arguments[1] : undefined;
  switch (action.type) {
    case _actions.UPDATE_ACTIVITY_MENU_VISIBLE:
      return state.set('activityMenuVisible', action.payload.isActivityMenuVisible);
    case _actions.UPDATE_ACTIVITY_TYPE:
      return state.set('primaryActivityType', action.payload.type).set('secondaryActivityType', null).setIn(['status', 'activityMenuVisible'], false);
    case _actions.UPDATE_ACTIVITY_TYPE_SECONDARY:
      return state.set('secondaryActivityType', action.payload.type).setIn(['status', 'activityMenuVisible'], false);
    case _actions.TOGGLE_ACTIVITY_MENU_VISIBLE:
      return state.setIn(['status', 'activityMenuVisible'], !state.getIn(['status', 'activityMenuVisible']));
    case _actions.FETCHING_SPACE_DETAILS:
      return state.setIn(['status', 'isFetchingSpaceDetails'], true);
    case _actions.STORE_SPACE_DETAILS:
      return state.setIn(['status', 'isFetchingSpaceDetails'], false).set('spaceDetails', (0, _immutable.fromJS)((0, _assign.default)({}, action.payload.details)));
    case _actions.STORE_ACTIVITY_TYPES:
      {
        return state.set('activityTypes', (0, _immutable.fromJS)(action.payload.activityTypes));
      }
    case _actions.STORE_DESTINATION:
      {
        return state.set('destination', new Destination(action.payload));
      }
    case _actions.UPDATE_WIDGET_STATUS:
      {
        return state.mergeIn(['status'], action.payload.status);
      }
    case _actions.RELOAD_WIDGET:
      {
        return state.setIn(['status', 'shouldReloadWidget'], false).set('destination', null).set('spaceDetails', null);
      }
    default:
      return state;
  }
}
var reducers = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, _widgetMessage.reducers), _widgetMeet.reducers), _widgetRoster.reducers), {}, {
  errors: _reduxModuleErrors.default,
  features: _reduxModuleFeatures.default,
  users: _reduxModuleUsers.default,
  mercury: _reduxModuleMercury.default,
  media: _reduxModuleMedia.default,
  spaces: _reduxModuleSpaces.default,
  widgetSpace: reducer
});
var _default = exports.default = reducers;