import { useState } from "react"; import { getQuizDataAI } from "./quizRelase"; import { addQuestion, useQuizStore } from "@/stores/useQuizStore"; export const useQuizGetNext = () => { const { quizId, settings } = useQuizStore(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [currentPage, setCurrentPage] = useState(1); const loadMoreQuestions = async () => { if (settings.status === "ai") { setIsLoading(true); setError(null); try { const data = await getQuizDataAI(quizId); const newQuestion = data?.questions[0]; if (newQuestion) { newQuestion.page = currentPage; addQuestion(newQuestion); setCurrentPage((old) => old++); return newQuestion; } } catch (err) { setError(err as Error); } finally { setIsLoading(false); } } }; return { loadMoreQuestions, isLoading, error, currentPage }; };