import axios from "axios";

function transf(json) {
  let map = new Map();
  for (const v of json) {
    let set = new Set();
    for (const c of v.children) {
      set.add(c.name);
    }
    map.set(v.name, set);
  }
  return map;
}

export async function getJobCate() {
  const res = await axios.get(`/job_classifies.json`);
  return transf(res.data.data);
}
export async function getJobCate2() {
  const json = (await axios.get(`/job_classifies.json`)).data.data;
  let map = new Map();
  for (const v of json) {
    let innerMap = new Map();
    for (const c of v.children) {
      innerMap.set(c.name, { job_classify_root: v.name, job_classify: c.name });
    }
    map.set(v.name, innerMap);
  }
  return map;
}

export const mock = transf([
  {
    name: "后端开发",
    children: [
      { name: "Java" },
      { name: "C++" },
      { name: "Php" },
      { name: "Go" },
    ],
  },
  {
    name: "前端开发",
    children: [
      { name: "web前端" },
      { name: "html5" },
      { name: "Php" },
      { name: "JavaScript" },
    ],
  },
]);