import {reactive, ref} from 'vue';
import useLoading from "~/store/loading";
import request from "~/utils/request";
import {showFailToast} from "vant";
import useUser from "~/store/user";
import {UserRelTypes} from "~/types";


const store = reactive({
    subsidiaries: []
})
export default function useSupervisor() {
    const { load_start, load_done } = useLoading();
    const {store:{current}} = useUser();



    async function getSubsidiaries() {
        load_start()
        const {r, d, e} = await request({
            url: `/api/v1/uc/find_all_user_rels_by_params`, data: {from_user_id: current.hty_id, rel_type: UserRelTypes.TeacherToTeacher}
        });
        load_done()
        if (r) {
            store.subsidiaries = d;
        } else {
            store.subsidiaries = [];
            showFailToast(e);
        }
    }

    return {
        getSubsidiaries, store
    }
}
