import { defineStore } from 'pinia'
import { getConfigListApi } from '@/service/config'
import { until } from '@vueuse/core'

export const useDictStore = defineStore(
  'dict',
  () => {
    // 获取配置列表
    const getConfigList = async (groupname: string) => {
      const { data: configList, loading } = useRequest(
        () => getConfigListApi({ groupname }, { pageindex: 1, rows: 999 }),
        {
          immediate: true,
        },
      )

      await until(loading).toBe(false)
      return configList.value.Data
    }

    return {
      getConfigList,
    }
  },
  {
    persist: true,
  },
)
