import { DictVO } from '@/api/interface/system/dict'
import { pinia } from '../index'
import DictApi from '@/api/module/system/dict'
export const useOptionsStore = defineStore('eco-dict-options', {
  state: () => ({
    isLoaded: false as boolean,
    dictOptions: {} as Record<string, DictVO[]>
  }),
  getters: {
    getDictOptionsAll: state => state.dictOptions
  },
  actions: {
    async setAllDictMap() {
      if (this.isLoaded) return
      const { data } = await DictApi.map()
      this.dictOptions = data
      this.isLoaded = true
    },
    getDictOptions(dictLabel: string) {
      return this.dictOptions[dictLabel] || []
    },
    setReloadOptions() {
      this.isLoaded = false
    }
  },
  persist: true
})

export const useOptionsStoreWithOut = () => {
  return useOptionsStore(pinia)
}
