import { defineStore } from 'pinia';
import { ref } from 'vue'
import { getDictionary } from '@/api/sys/categories';

export const useFormCallStore = defineStore('formCall', () => {
  const dictionary = ref({})
  async function getDictionaryOptions(code){
    if(Object.keys(dictionary.value).includes(code)){
      return dictionary.value[code]
    }else{
      let params = { code }
      let res = await getDictionary(params)
      let data: any[] = []
      res.forEach(item => {
        data.push({
          value: item.itemValue,
          label: item.itemName,
        })
      })
      dictionary.value[code] = data
      return data
    }
  }
  function clearData () {
    dictionary.value = {}
  }
  return { dictionary, getDictionaryOptions, clearData }
})