import { ref } from 'vue';
export { useTopicMode } from './mode';
export { useAudioSet } from './audio';
import { useSubjectList } from './list';
import { useSubjectCheck } from './wrong';

export const useSubjectShowLogic = (type: ExerciseType.ListType) => {
	const { subjectList, subjectTotal, loadNewSubject, currentSubject, currentSubjectIndex } = useSubjectList(type); //获取题目列表

	/**下一题数据请求锁 */
	const nextBtnState = ref(true);

	/** 展示下一题 */
	const nextSubject = async () => {
		if (currentSubjectIndex.value < subjectList.value.length - 1) {
			currentSubjectIndex.value++;
		} else {
			if (nextBtnState.value) {
				//禁用下一题按钮
				nextBtnState.value = false;
				//题目数量不足加载数据
				await loadNewSubject();
				//启用按钮
				nextBtnState.value = true;
			}
		}
	};

	/** 展示上一题  */
	const lastSubject = () => {
		currentSubjectIndex.value > 0 && currentSubjectIndex.value--;
	};

	const { trueNum, falseNum, isJumpNext, userAnswerChange, addCurrentQuestion } = useSubjectCheck(currentSubject, nextSubject);

	return {
		currentSubject,
		currentSubjectIndex,
		subjectTotal,
		nextSubject,
		lastSubject,
		trueNum,
		falseNum,
		isJumpNext,
		userAnswerChange,
		addCurrentQuestion,
	};
};
