import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistedState from 'vuex-persistedstate'
import config from '../js/config'
import common from './common'
import user from './user'
import http from './http'

Vue.use(Vuex)

const vuexLocal = new VuexPersistedState({
    key: config.appEnv + '_vuex',
    storage: {
        getItem: key => uni.getStorageSync(key),
        setItem: (key, value) => uni.setStorageSync(key, value),
        removeItem: key => uni.removeStorageSync(key),
    },
})

let store = new Vuex.Store({
    strict: process.env.NODE_ENV !== 'production',
    plugins: [vuexLocal],
    modules: {
        'common': common,
        'user': user,
        'http': http,
    },
})

export default store
