import { ref } from 'vue';
import {
  DEFAULT_LABEL,
  ABLE_TYPE,
  ROLE_TYPE,
  TASK_STATUS,
} from '@/constants/enumerate';
import { dictToOption } from '@/utils/utils';
import { Options } from '@/types/global';

const dicts = {
  ABLE_TYPE,
  ROLE_TYPE,
  TASK_STATUS,
};

type DictTypeType = keyof typeof dicts;

export default function useDictOption(dictType: DictTypeType) {
  const optionList = ref<Options[]>(dictToOption(dicts[dictType] || {}));

  function getLabel(val: string): string {
    // @ts-ignore
    return dicts[dictType] ? dicts[dictType][val] : DEFAULT_LABEL;
  }

  return {
    optionList,
    getLabel,
  };
}
