import { globalStore } from '@/stores'
import { ArrToObj } from '@/utils/tool'

export const getDict = (code: string, full = false, { label, value }: anyObj = {}) => {
  const { dict } = globalStore()

  const d = dict.find((i: anyObj) => i.code === code)
  let dictData = d ? d.children : []
  if (label && value) {
    dictData = dictData.map((i: anyObj) => ({
      label: i[label],
      value: i[value],
    }))
  }
  if (full) {
    return {
      dictData,
      dictObj: ArrToObj(dictData, 'value', 'code'),
      enum: ArrToObj(dictData, 'code', 'value'),
      remarkObj: ArrToObj(dictData, 'code', 'remark'),
    }
  }
  return dictData
}
