import { getGradeClassTreeApi, getDictTreeApi } from "@/api/smartCampus/index";
export const getSelectDownData = async (type, dictType) => {
  let options;
  switch (type) {
    case "sex":
      // 性别
      options = [
        { value: 0, label: "男" },
        { value: 1, label: "女" },
      ];
      break;
    case "relation":
      // 家长和学生关系
      options = [
        { value: 1, label: "父亲" },
        { value: 2, label: "母亲" },
        { value: 3, label: "爷爷" },
        { value: 4, label: "奶奶" },
        { value: 5, label: "外公" },
        { value: 6, label: "外婆" },
        { value: 7, label: "哥哥" },
        { value: 8, label: "姐姐" },
        { value: 9, label: "其他" },
      ];
      break;
    case "subject":
      // 学科
      options = [
        { value: "英语", label: "英语" },
        { value: "数学", label: "数学" },
        { value: "语文", label: "语文" },
        { value: "物理", label: "物理" },
        { value: "化学", label: "化学" },
        { value: "生物", label: "生物" },
        { value: "地理", label: "地理" },
        { value: "历史", label: "历史" },
        { value: "政治", label: "政治" },
        { value: "体育", label: "体育" },
        { value: "美术", label: "美术" },
        { value: "计算机", label: "计算机" },
        { value: "音乐", label: "音乐" },
      ];
      break;

    case "gradeClassTree":
      // 年级班级
      let res = await getGradeClassTreeApi();
      let data = res.data;
      if (data.length > 0) {
        options = [{ name: "全部", id: "", children: [] }];
        // 处理年级班级数据
        for (let i in data) {
          if (data[i].scClassVos && data[i].scClassVos.length > 0) {
            let classVos = data[i].scClassVos;
            let _scClassVos = [];
            for (let j in classVos) {
              _scClassVos.push({ ...classVos[j], name: classVos[j].name });
            }
            options[0].children.push({
              ...data[i],
              name: data[i].name,
              children: _scClassVos,
            });
          } else {
            options[0].children.push({
              ...data[i],
              name: data[i].name,
            });
          }
        }
      }
      break;
    case "dict":
      // 字典查询
      let res1 = await getDictTreeApi();
      if (res1.code === 200) {
        let allDict = res1.data;
        options = allDict.filter((item) => item.dictType === dictType);
      }
      break;
  }
  return options;
};
// 获取学生班级
export const useFetchGradeClassTree = async (info) => {
  let options = [{ name: "全部", id: "", children: [] }];
  const tenantId = info.tenantId;
  let res = await getGradeClassTreeApi({ tenantId });
  let data = res.data;
  if (data.length > 0) {
    // 处理年级班级数据
    for (let i in data) {
      if (data[i].scClassVos && data[i].scClassVos.length > 0) {
        let classVos = data[i].scClassVos;
        let _scClassVos = [];
        for (let j in classVos) {
          _scClassVos.push({ ...classVos[j], name: classVos[j].name });
        }
        options[0].children.push({
          ...data[i],
          name: data[i].name,
          children: _scClassVos,
        });
      } else {
        options[0].children.push({
          ...data[i],
          name: data[i].name,
        });
      }
    }
  }
  return options;
};
