/**
 * 用户存储全局一些 状态 和 类型的数据词典
 */
import {defineStore} from "pinia";
import {DictApi} from "/@/api/admin/Dict";

/**
 * 数据词典的缓存编码
 * */
const arr =
  ['componentStatus',
    'componentType',
    'componentStatusType',
    'componentTypeListStatus',
    'productionLogListStatus',
    'groupLogoKeyKeyType',
    'groupKeyGroupStatus',
    'softwareType',
    'equipmentType',
    'softwarePackageStatus',
    'oilEngineStatus'
  ]

export const useGlobalCacheStore = defineStore('globalCacheStore', {
  state: () => ({
    globalStore:new Map
  }),
  actions: {
    /**获取所有字典缓存*/
    async requestGlobalStore  ()  {
      const { data } = await new DictApi().getList(arr)
      Object.keys(data as object).forEach(key => {
        const newMap = data?.[key]?.reduce((map, obj) => {
          // @ts-ignore
          obj.color = obj.code?.split("_")[1] ?? ''
          map.set(obj.value,{...obj})
          return map
        },new Map)
        this.globalStore.set(key,newMap)
      })
    },

    getGlobalStore(){
      return this.globalStore
    },

  }
})
