export default function createEnum(dictList) {
  const valueToItemMap = {};
  const nameToItemMap = {};
  dictList.forEach((dictItem) => {
    nameToItemMap[dictItem["name"]] = dictItem;
    valueToItemMap[dictItem["value"]] = dictItem;
  });

  return {
    ...nameToItemMap,
    options: dictList,
    getValueByName(enumName) {
      return nameToItemMap && nameToItemMap[enumName].value;
    },
    getLabelByValue(value) {
      return valueToItemMap[value] && valueToItemMap[value].label || '';
    },
    getLabelByName(name) {
      return nameToItemMap && nameToItemMap[name].label
    },
    getTagByValue(value) {
      return valueToItemMap[value] && valueToItemMap[value].tag || ''
    }
  };
}
// 角色状态
export const RULE_STATUS = createEnum([
  {
    value: 0,
    label: "启用",
    name: "enabled",
  },
  {
    value: 1,
    label: "停用",
    name: "disabled",
  },
]);

// 账号状态
export const ACCOUNT_STATUS = createEnum([
  {
    value: 0,
    label: "启用",
    name: "enabled",
  },
  {
    value: 1,
    label: "停用",
    name: "disabled",
  },
]);

// 院区状态
export const WARD_STATUS = createEnum([
  {
    value: 0,
    label: "启用",
    name: "enabled",
  },
  {
    value: 1,
    label: "停用",
    name: "disabled",
  },
])
// 是否为本院区
export const IS_MY_HOSPITAL = createEnum([
  {
    value: 1,
    label: "是",
    name: "is"
  },
  {
    value: 0,
    label: "否",
    name: "no"
  }
])
// 随访单状态
export const FOLLOWUP_STATUS = createEnum([
  {
    value: 0,
    label: '待开始',
    name: 'be_start',
    tag: 'warning'
  },
  {
    value: 1,
    label: '进行中',
    name: 'underway',
    tag: 'success'
  },
  {
    value: 2,
    label: '已完成',
    name: 'finished',
    tag: 'info'
  },
  {
    value: 3,
    label: '已过期',
    name: 'past',
    tag: 'info',
  },
  {
    value: 4,
    label: '已终止',
    name: 'termination',
    tag: 'danger'
  }
])
// 待办事项类型
export const TODO_TYPE = createEnum([
  {
    value: 1,
    label: '随访问卷',
    name: 'survey'
  },
  {
    value: 2,
    label: '患教文章',
    name: 'article'
  },
  {
    value: 3,
    label: '备注',
    name: 'remark'
  },
  {
    value: 4,
    label: '提醒',
    name: 'remind'
  }
])
// 待办事项状态
export const TODO_STATUS = createEnum([
  {
    value: 0,
    label: '未完成',
    name: 'unfinished'
  },
  {
    value: 1,
    label: '已完成',
    name: 'finished'
  }
])
// 文章创作类型
export const ARTICLE_TYPE = createEnum([
  {
    label: '内容编辑',
    value: 0,
    name: 'edit'
  },
  {
    label: '链接',
    value: 1,
    name: 'link'
  }
])
//  日期单位
export const PERIOD_UNIT = createEnum([
  {
    label: '天',
    value: 0,
    name: 'day'
  },
  {
    label: '月',
    value: 1,
    name: 'month'
  },
  {
    label: '年',
    value: 2,
    name: 'year'
  }
])
