import { listDictionaries, pageDictionaryData } from '@/api/sys';
import dict from '@/enum/dict';

export async function sysDict(name, value) {
  const code = dict[name];
  let names = '';

  try {
    const res = await listDictionaries({ pageNum: 1, size: 10, code: code });
    const id = res.list[0].id;

    const rep = await pageDictionaryData(id);
    const list = rep.data.dictStaticVOList;

    for (const key in list) {
      if (list[key].code == value) {
        names = list[key].name;
        break;
      }
    }
  } catch (error) {
    console.error('Error fetching dictionary data:', error);
  }

  return names;
}

export function isExit(value, obj) {
  console.log(value);
  if (value != '') {
    return value == '0' ? obj.isFalse : obj.isTrue;
  }
  return null;
}
