import { combineReducers, createStore } from 'redux'
import { persistReducer, persistStore } from 'redux-persist'
import reducers from './reducers'
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'
import AsyncStorage from '@react-native-async-storage/async-storage'

import createEncryptor from 'redux-persist-transform-encrypt'

const k = 'oafsjeojasofjwoefjjforFOJISEOfisweofijmowefjoewjfJFOIeofjPOAFJIefjOIJFoiQJAEW'
const encryptor = createEncryptor({
  secretKey: k,
  onError: function (error) {
    // Handle the error.
  }
})
const persistConfig = {
  key: 'app',
  storage: AsyncStorage,
  whitelist: ['app'],
  stateReconciler: autoMergeLevel2,
  transforms: [encryptor]
}
var combindedReducers = combineReducers(reducers)
const persistedReducer = persistReducer(persistConfig, combindedReducers)

export const store = createStore(
  persistedReducer,
)
export const persistor = persistStore(store)