import { defineStore } from 'pinia'

export const useLangStore = defineStore('lang', {
  state: () => {
    return {
      language: localStorage.getItem('lang') || 'zhCN',
    }
  },
  actions: {
    changeLang(data) {
      this.language = data
    },
  },
  persist: {
    key: 'lang',
    storage: localStorage,
    serializer: {
      serialize: (state) => state.language,
      deserialize: (value) => ({
        language: value || 'zhCN',
      }),
    },
  },
})