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

export default function useUsers() {
	const [users, setUsers] = useState<User[]>([]);
	const [isLoading, setIsLoading] = useState(false);
	const [isError, setIsError] = useState(false);

	const getData = () => {
		setIsLoading(true);
		axios
			.get<User[]>("/api/users/list")
			.then((response) => setUsers(response.data))
			.finally(() => setIsLoading(false));
	};

	useEffect(getData, []);

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