import { configureStore } from '@reduxjs/toolkit';
import { useDispatch, useSelector, type TypedUseSelectorHook } from 'react-redux';

import inventoryReducer from '../../../store/inventorySlice';
import groupDetailReducer from './groupDetailSlice';
import groupsListReducer from './groupsListSlice';

export const store = configureStore({
  reducer: {
    groupsList: groupsListReducer,
    groupDetail: groupDetailReducer,
    // Shared inventory-attributes slice, consumed by the common InventoryFilter.
    inventory: inventoryReducer
  }
});

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
export const useAppDispatch = () => useDispatch<AppDispatch>();

export default store;
