import {GET_EDUCATIONS_LIST} from "@/core/data/apiRoutes";
import {useRequest} from "@witel/webapp-builder";
import {useEffect, useState} from "react";

const useEducations = () => {
    const [isLoadingEducationsList, setIsLoadingEducationsList] = useState(false)
    const [errorEducationsList, setErrorEducationsList] = useState(false)
    const [educationsList, setEducationsList] = useState([])
    const requestServer = useRequest({auth: true, notification: false})

    useEffect(() => {
        setIsLoadingEducationsList(true)
        requestServer(GET_EDUCATIONS_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
            setIsLoadingEducationsList(false)
            setEducationsList(data.data);
        }).catch(() => {
            setIsLoadingEducationsList(false)
            setErrorEducationsList(true)
        })
    }, [])

    return {
        educationsList,
        isLoadingEducationsList,
        errorEducationsList
    }
};

export default useEducations;