import {Exam} from "@/interfaces/exam";
import axios from "axios";
import {useEffect, useState} from "react";

export default function useExams() {
	const [exams, setExams] = useState<Exam[]>([]);
	const [isLoading, setIsLoading] = useState(false);
	const [isError, setIsError] = useState(false);

	useEffect(() => {
		setIsLoading(true);
		axios
			.get<Exam[]>("/api/exam")
			.then((response) => setExams(response.data))
			.finally(() => setIsLoading(false));
	}, []);

	return {exams, isLoading, isError};
}
