'use strict';

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

exports.default = function () {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
  var _ref = arguments[1];
  var type = _ref.type,
      payload = _ref.payload;

  var newState = void 0;
  switch (type) {
    case 'TOGGLE_FILTER_PANE':
      newState = state.showFilterPane ? (0, _objectAssign2.default)({}, state, { showFilterPane: false }) : (0, _objectAssign2.default)({}, state, { showFilterPane: true });
      break;

    case 'SWITCH_VIEW':
      newState = state.activeView === payload ? state : (0, _objectAssign2.default)({}, state, { activeView: payload });
      break;

    case 'OPEN_SETTINGS':
      newState = state.activeModal === 'settings' && state.settingsTab === payload ? state : (0, _objectAssign2.default)({}, state, { activeModal: 'settings', settingsTab: payload });
      break;

    case 'CLOSE_MODAL':
      newState = !state.activeModal ? state : (0, _objectAssign2.default)({}, state, { activeModal: null });
      break;

    case 'SHOW_FEATURE_DETAIL':
      newState = state.activeModal === 'feature' && state.featureId === payload ? state : (0, _objectAssign2.default)({}, state, { activeModal: 'feature', featureId: payload });
      break;

    case 'REDIRECT_VIEW':
      newState = (0, _objectAssign2.default)({}, state, { activeView: payload, activeModal: null, redirect: true });
      break;

    default:
      newState = state;
      break;
  }
  if (newState !== state && type !== 'REDIRECT_VIEW' && state.redirect) {
    newState.redirect = false;
  }
  return newState;
};

var _objectAssign = require('object-assign');

var _objectAssign2 = _interopRequireDefault(_objectAssign);

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

// The current UI state of the app
var defaultState = {
  // The current main view of the data
  activeView: undefined,
  // The current open modal
  activeModal: null,
  // Whether the filter pane is shown or hidden
  showFilterPane: true,
  // The current tab of the settings modal (if open)
  settingsTab: null,
  // The id of the feature to show in the feature modal (if open)
  featureId: null,
  // redirect is true if the ui state was invalid and was redirected to a valid state
  redirect: false
};
//# sourceMappingURL=ui.js.map