import { combineReducers, createStore } from 'redux';
import { chartReducer, initialChartState } from './chart.js';
export { ChartActions } from './chart.js';
import { modalReducer, ModalActions, initialModalState } from './modal.js';

const appReducer = combineReducers({
  chart: chartReducer,
  modal: modalReducer
});
const rootReducer = (state, action) => {
  if (action.type === "RESET_UI_KIT_STORE") {
    state = {
      modal: initialModalState,
      chart: initialChartState
    };
  }
  return appReducer(state, action);
};
const UIKitStore = createStore(rootReducer);
function pushModal(modal) {
  UIKitStore.dispatch({
    type: ModalActions.PUSH_MODAL,
    payload: modal
  });
}
function popModal() {
  UIKitStore.dispatch({
    type: ModalActions.POP_MODAL
  });
}
function closeModal(id) {
  UIKitStore.dispatch({
    type: ModalActions.CLOSE_MODAL,
    id
  });
}

export { ModalActions, UIKitStore, chartReducer, closeModal, initialChartState, initialModalState, modalReducer, popModal, pushModal, rootReducer };
