import {GET_PROVINCE_LIST} from "@/core/data/apiRoutes";
import useRequest from "@/lib/app/hooks/useRequest";
import useSWR from "swr";

const useProvince = () => {
    const requestServer = useRequest({auth: true, notification: false})

    //swr config
    const fetcher = (...args) => {
        return requestServer(args, 'get').then(({data}) => {
            return data;
        }).catch(() => {
        })
    };

    const {data, isLoading} = useSWR(GET_PROVINCE_LIST, fetcher, {
        revalidateIfStale: false,
        revalidateOnFocus: false,
        revalidateOnReconnect: false,
        keepPreviousData: true
    });

    return {
        provinceList: data,
        isLoadingProvinceList: isLoading,
        errorProvinceList: !data
    }
};

export default useProvince;