import { configureStore } from '@reduxjs/toolkit';
import { useDispatch, useSelector } from 'react-redux';
import searchSlice from './slices/search';
import doctorSlice from './slices/doctor';
import filterSlice from './slices/filter';
import configSlice from './slices/config';
import commonSlice from './slices/common';
import cacheSlice from './slices/cache';
import localStorage from 'redux-persist/lib/storage';
import sessionStorage from 'redux-persist/lib/storage/session';
import { persistStore, persistReducer, FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER, } from 'redux-persist';
import { getHostEnv } from 'src/lib/utils';
var searchPersistConfig = {
    key: 'search',
    storage: sessionStorage,
    whitelist: ['address'],
};
var filterPersistConfig = {
    key: 'filter',
    storage: sessionStorage,
    whitelist: ['filters', 'landingFilters', 'resultFilters'],
};
var commonPersistConfig = {
    key: 'common',
    storage: localStorage,
    whitelist: ['zipLatLng', 'comingFromInsideApp', 'partner'],
};
var cachePersistConfig = {
    key: 'cache',
    storage: sessionStorage,
};
var persistedSearchSlice = persistReducer(searchPersistConfig, searchSlice);
var persistedFilterSlice = persistReducer(filterPersistConfig, filterSlice);
var persistedCommonSlice = persistReducer(commonPersistConfig, commonSlice);
var persistedCacheSlice = persistReducer(cachePersistConfig, cacheSlice);
// Optimize Redux DevTools for production
var getDevTools = function () {
    var hostEnv = getHostEnv();
    // Only enable in development
    if (hostEnv === 'production')
        return false;
    if (hostEnv === 'test')
        return false;
    return process.env.REACT_APP_LOCAL_REDUX_DEV_TOOLS;
};
export var store = configureStore({
    reducer: {
        search: persistedSearchSlice,
        doctor: doctorSlice,
        filter: persistedFilterSlice,
        config: configSlice,
        common: persistedCommonSlice,
        cache: persistedCacheSlice,
    },
    devTools: getDevTools(),
    middleware: function (getDefaultMiddleware) {
        return getDefaultMiddleware({
            serializableCheck: {
                ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
                ignoredPaths: [
                    'search.result',
                    'doctor.result',
                    'cache', // Add cache to ignored paths
                    'config.config', // Add large config objects
                ],
            },
            immutableCheck: {
                ignoredPaths: ['search.result', 'doctor.result', 'cache', 'config.config'],
            },
        });
    },
});
export var persistor = persistStore(store);
export var useAppDispatch = function () { return useDispatch(); };
export var useAppSelector = useSelector;
