import { configureStore } from "@reduxjs/toolkit";

import cartSlice, {CartState} from "./slices/cart-slice";
import userSlice from "./slices/user-slice";
import addToCartDialogReducer from "./slices/addToCartDialogSlice";

// export const store = configureStore({
//   reducer: {
//     cartDetail: cartSlice,
//     user: userSlice,
//     addToCartDialog: addToCartDialogReducer,
//     currencyList: currencySlice
//   },
// });

// export type RootState = ReturnType<typeof store.getState>;
// export type AppDispatch = typeof store.dispatch;
export interface PreloadedStateType { 
  cartDetail: CartState; 
}
export const makeStore = (preloadedState: PreloadedStateType) => {
    return configureStore({
      reducer: {
        cartDetail: cartSlice,
        user: userSlice,
        addToCartDialog: addToCartDialogReducer,
      },
      preloadedState
    });
}
// Infer the type of makeStore
export type AppStore = ReturnType<typeof makeStore>
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<AppStore['getState']>
export type AppDispatch = AppStore['dispatch']


