import { configureStore, createSlice, Middleware } from "@reduxjs/toolkit";
import { mainSlice } from "./mainSlice";
import { createLogger } from "redux-logger";
import logger from "../utils/logger";

export * from './mainSlice'

const store = configureStore({
  middleware: (getDefaultMiddleware) => {
    const extra: Middleware[]  = []
    if (process.env.HYEXT_BUILD_ENV !== 'production') {
      extra.push(createLogger())
    }
    return getDefaultMiddleware().concat(extra)
  },
  reducer: {
    main: mainSlice.reducer
  }
})

store.subscribe(() => {
  logger.log('store update', store.getState())
})


export type StoreState = ReturnType<typeof store.getState>

export default store