/*
 * @Author: zhanyoulin<zhanyoulin456@163.com>
 * @Date: 2023-06-13 09:41:17
 * @LastEditors: zhanyoulin
 * @LastEditTime: 2023-06-16 17:32:44
 * @Description:
 */
import { defineStore } from 'pinia'
import { GlobalState } from '@/stores/interface'
import piniaPersistConfig from '@/config/piniaPersist'

export const useGlobalStore = defineStore({
  id: 'global',
  // 修改默认值之后，需清除 localStorage 数据
  state: (): GlobalState => ({
    // 折叠菜单
    isCollapse: false,
    // 暗黑模式
    isDark: false
  }),
  getters: {},
  actions: {
    // Set GlobalState
    setGlobalState(...args: ObjToKeyValArray<GlobalState>) {
      this.$patch({ [args[0]]: args[1] })
    }
  },
  persist: piniaPersistConfig('global')
})
