import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'

import config from '@/config'
import { deserialize, serialize } from '@cacp/ui'

const pinia = createPinia()
pinia.use(
  createPersistedState({
    auto: true,
    storage: sessionStorage,
    key: (id) => `__${config.SERVICE_ID}__${id}`,
    serializer: {
      deserialize: deserialize,
      serialize: serialize
    }
  })
)

export default pinia
