import { defineStore } from 'pinia'

import { getDictionaries as _getDictionaries } from '#/api/global'

export const useGlobalInfo = defineStore('global', {
  state: (): {
    config: anyObj
    dictionaries: anyObj[]
    isSelectPattern: boolean
  } => ({
    dictionaries: [], // 字典
    config: {
      modularId: 3, // 模块ID
    }, // 用户个性化配置
    isSelectPattern: false, // 是否选择学习模式
  }),
  actions: {
    // 获取字典
    async getDictionaries() {
      this.dictionaries = await _getDictionaries()
    },
    // 清理用户数据
    clearData() {
      this.dictionaries = []
    },
  },
})
