import _objectSpread from "@babel/runtime/helpers/objectSpread";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

var _checkedState;

import { ACTIONS, CONTROLS_KEYS, VIEW_TYPES } from './constants';
var DefaultState = {
  switches: [{
    name: 'Source',
    key: CONTROLS_KEYS.SOURCE_DIAGRAM_ON,
    children: [{
      name: 'close all',
      title: 'Close folders to 2nd Level',
      key: CONTROLS_KEYS.SOURCE_COLLAPSE_TO_MIN,
      type: VIEW_TYPES.BUTTON
    }, {
      name: 'open all',
      title: 'Open all folders',
      key: CONTROLS_KEYS.SOURCE_EXPAND_ALL,
      type: VIEW_TYPES.BUTTON
    }, {
      name: 'active only',
      title: 'Keep opened only folders with active files',
      key: CONTROLS_KEYS.SOURCE_KEEP_ONLY_ACTIVE_ITEMS
    }, {
      name: 'dim source',
      title: 'Dim source tree folders',
      key: CONTROLS_KEYS.SOURCE_DIM_FOLDERS
    }, {
      name: 'explorer',
      title: 'Show explorer',
      key: CONTROLS_KEYS.SOURCE_EXPLORER_BAR
    }]
  }, {
    name: 'Dependencies',
    key: CONTROLS_KEYS.DEPENDENCIES_DIAGRAM_ON,
    children: [{
      name: 'direct only',
      title: 'Show One module dependencies',
      key: CONTROLS_KEYS.DEPENDENCIES_SHOW_DIRECT_ONLY
    }]
  }, {
    name: 'CodeCrumbs',
    key: CONTROLS_KEYS.CODE_CRUMBS_DIAGRAM_ON,
    children: [{
      name: 'minimize',
      title: 'Minimize code crumbs',
      key: CONTROLS_KEYS.CODE_CRUMBS_MINIMIZE
    }, {
      name: 'details',
      title: 'Show details',
      key: CONTROLS_KEYS.CODE_CRUMBS_DETAILS
    }, {
      name: 'code preview',
      title: 'Code preview',
      key: CONTROLS_KEYS.CODE_CRUMBS_CODE_PREVIEW
    }, {
      name: 'line numbers',
      title: 'Show crumbed line numbers',
      key: CONTROLS_KEYS.CODE_CRUMBS_LINE_NUMBERS
    }]
  }, {
    name: 'SideBar',
    key: CONTROLS_KEYS.SIDE_BAR,
    children: []
  }],
  checkedState: (_checkedState = {}, _defineProperty(_checkedState, CONTROLS_KEYS.SOURCE_DIAGRAM_ON, true), _defineProperty(_checkedState, CONTROLS_KEYS.DEPENDENCIES_SHOW_DIRECT_ONLY, true), _defineProperty(_checkedState, CONTROLS_KEYS.CODE_CRUMBS_LINE_NUMBERS, true), _defineProperty(_checkedState, CONTROLS_KEYS.CODE_CRUMBS_DETAILS, true), _checkedState),
  disabledState: {},
  valuesState: {
    diagramZoom: 1,
    selectedTabInSideBar: 'Code'
  }
};
export default (function () {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DefaultState;
  var action = arguments.length > 1 ? arguments[1] : undefined;

  switch (action.type) {
    case ACTIONS.SET_FULL_STATE:
      return _objectSpread({}, state, action.payload);

    case ACTIONS.TOGGLE_SWITCH:
      var _action$payload = action.payload,
          switchKey = _action$payload.switchKey,
          checked = _action$payload.checked;
      return _objectSpread({}, state, {
        checkedState: _objectSpread({}, state.checkedState, _defineProperty({}, switchKey, checked))
      });

    case ACTIONS.SET_DISABLED_CONTROL:
      var _action$payload2 = action.payload,
          controlKey = _action$payload2.controlKey,
          disabled = _action$payload2.disabled;
      return _objectSpread({}, state, {
        disabledState: _objectSpread({}, state.disabledState, _defineProperty({}, controlKey, disabled))
      });

    case ACTIONS.SELECT_SIDE_BAR_TAB:
      return _objectSpread({}, state, {
        valuesState: _objectSpread({}, state.valuesState, {
          selectedTabInSideBar: action.payload
        })
      });

    case ACTIONS.SET_ZOOM:
      return _objectSpread({}, state, {
        valuesState: _objectSpread({}, state.valuesState, {
          diagramZoom: Math.round(action.payload * 10) / 10
        })
      });

    default:
      return state;
  }
});