import { configureStore } from "@reduxjs/toolkit";
import { setupListeners } from "@reduxjs/toolkit/query";
import { sideMenuSlice } from "../components/SideMenu/sideMenuSlice";
import { lessonPageEditorSlice } from "../../features/Lessons/LessonPageEditor/lessonPageEditorSlice";
import { appSlice } from "../reducers/appSlice";
import { lessonsApi } from "core/services/lessons";
import { teamApi } from "core/services/team";

const makeStore = (/* preloadedState */) => {
  const store = configureStore({
    reducer: {
      app: appSlice.reducer,
      sideMenu: sideMenuSlice.reducer,
      lessonPageEditor: lessonPageEditorSlice.reducer,
      [lessonsApi.reducerPath]: lessonsApi.reducer,
      [teamApi.reducerPath]: teamApi.reducer,
    },
    // preloadedState,
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware().concat(
        lessonsApi.middleware,
        teamApi.middleware
      ),
  });

  setupListeners(store.dispatch);
  return store;
};

export const store = makeStore();
