import type { Ref } from 'vue'

/**
 * 字典映射
 * @param dictList 字典列表
 * @example 使用示例
 * const { dictNameMap } = useDictName(dictList)
 * const label = dictNameMap('value')
 */
export const useDictName = (dictList: Ref<Array<{ label: string; value: ID }>>) => {
  const dictNameMap = (value: string) => {
    return dictList.value.find((item) => item.value === value)?.label || value
  }

  return {
    dictNameMap,
  }
}
