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

const useOccupations = () => {
    const [isLoadingOccupationsList, setIsLoadingOccupationsList] = useState(false)
    const [errorOccupationsList, setErrorOccupationsList] = useState(false)
    const [occupationsList, setOccupationsList] = useState([])
    const requestServer = useRequest({auth: true, notification: false})

    useEffect(() => {
        setIsLoadingOccupationsList(true)
        requestServer(GET_OCCUPATIONS_LIST, 'get', {auth: true, notification: false}).then(({data}) => {
            setIsLoadingOccupationsList(false)
            setOccupationsList(data.data);
        }).catch(() => {
            setIsLoadingOccupationsList(false)
            setErrorOccupationsList(true)
        })
    }, [])

    return {
        occupationsList,
        isLoadingOccupationsList,
        errorOccupationsList
    }
};

export default useOccupations;