import {createStore, createLogger} from 'vuex'
import {store as permission, PermissionStore, PermissionState} from '@/store/modules/permission'
import {store as user, UserStore, UserState} from '@/store/modules/user'
import {store as portait, PortaitStore, PortaitState} from '@/store/modules/portait'

export interface RootState {
  permission: PermissionState
  user: UserState,
  portait:PortaitState
}

export type Store = PermissionStore<Pick<RootState, 'permission'>>
  & UserStore<Pick<RootState, 'user'>>  & PortaitStore<Pick<RootState, 'portait'>>

// Plug in logger when in development environment
const debug = process.env.NODE_ENV !== 'production'
const plugins = debug ? [createLogger({})] : []
// Plug in session storage based persistence
// plugins.push(createPersistedState({ storage: window.sessionStorage }))

export const store = createStore({
  plugins,
  modules: {
    permission,
    user,
    portait
  }
})

export function useStore(): Store {
  return store as Store
}
