import { ref } from 'vue';
import { DEFAULT_LABEL, PICTURE_TYPE } from '@/constants/enumerate';
import { dictToOption } from '@/utils/utils';
import { SelectOptions } from '@/types/global';

const dicts = {
  PICTURE_TYPE,
};

type DictTypeType = keyof typeof dicts;

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

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

  return {
    optionList,
    getLabel,
  };
}
