/**
 * 业务常量的使用方式扩展
 * @param {Array} source
 [
 { value: 1,label: '空间站',name: 'SPACE' },
 { value: 2, label: '实践任务', name: 'PRACTICE' },
 { value: 3, label: '其他系统', name: 'OTHERS' }
 ]
 @returns {Function} fn
 fn() ===> source
 fn(value) ===> label
 fn(value) ===> color
 */
export default function createEnum(source) {
  const enumMap = new Map()
  const colorMap = new Map()
  source.map(item => {
    enumMap.set(item.value, item.label)
    colorMap.set(item.value, item.color)
  })
  source.getColor = (key) => {
    return colorMap.get(key) || ''
  }
  source.getLabel = (key) => {
    return enumMap.get(key) || ''
  }
  source.getCode = (label) =>{
    for(let key in enumMap.keys()){
      if (enumMap.get(key)===label){
        return key
      }
    }
  }
  return source
}
