import { ClassItem, SchoolItem } from "@/types/user";
import { getClassList, getSchoolList } from "@/api/modules/user";
type SchoolForm = {
  schoolName: string;
  schoolId: number;
  className: string;
  classId: number;
}
export const useSchool = () => {
  const form = ref<Partial<SchoolForm>>({});
  const schoolList = ref<SchoolItem[]>([]);
  const classList = ref<ClassItem[]>([]);
  const loadClassData = (schoolId: number | undefined) => {
    if (!schoolId) {
      return;
    }
    form.value.schoolId = schoolId;
    getClassList({ schoolId: form.value.schoolId }).then(res => {
      classList.value = res.data;
    });
  }
  return {
    form,
    schoolList,
    classList,
    loadClassData
  };
}