import {Code, Group, User} from "@/interfaces/user";
import axios from "axios";
import {useEffect, useState} from "react";

export default function useUserBalance() {
	const [balance, setBalance] = useState<number>(0);
	const [isLoading, setIsLoading] = useState(false);
	const [isError, setIsError] = useState(false);

	const getData = () => {
		setIsLoading(true);
		axios
			.get<{balance: number}>(`/api/users/balance`)
			.then((response) => setBalance(response.data.balance))
			.finally(() => setIsLoading(false));
	};

	useEffect(getData, []);

	return {balance, isLoading, isError, reload: getData};
}
