import { useRequest } from 'vue-request';
import { deviceCanOut, deviceCanIn } from '@/api/sop';
import { ref, watch } from 'vue';
const apiMap = {
  deviceCanOut: [deviceCanOut, 'deviceNo', 'deviceNo'],
  deviceCanIn: [deviceCanIn, 'deviceNo', 'deviceNo'],
};

export default function (key) {
  const { data } = useRequest(apiMap[key][0], {
    manual: false,
  });
  const options = ref([]);
  watch(data, (val) => {
    options.value = val.map((item) => ({
      ...item,
      value: item[apiMap[key][1]],
      label: item[apiMap[key][2]],
    }));
  });
  return { options };
}
