import { ref, computed } from 'vue';
import { storeToRefs } from 'pinia';
import dbStore from '@/store/db';

export default function useJob() {
  const { jobMap } = storeToRefs(dbStore());
  const memberList = ref([]);
  const memberJob = computed(() => memberList.value.reduce((acc, item) => {
    const jobs = item && Array.isArray(item.job) ? item.job : [];
    const jobStr = jobs.map(jobId => jobMap.value[jobId]).filter(Boolean).join('、 ');
    acc[item.userid] = jobStr;
    return acc;
  }, {}))

  return { memberJob, memberList }
}
