// ============================================================
// Redux Store 配置
// 大厂模式：RTK configureStore + 类型安全的 hooks
// ============================================================

import { configureStore } from '@reduxjs/toolkit';
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
import { uiSlice } from './slices/ui.slice';
import { usersSlice } from './slices/users.slice';

export const store = configureStore({
  reducer: {
    ui: uiSlice.reducer,
    users: usersSlice.reducer,
  },
  devTools: process.env.NODE_ENV !== 'production',
});

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

/** 类型安全的 dispatch hook */
export const useAppDispatch = () => useDispatch<AppDispatch>();

/** 类型安全的 selector hook */
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
