import quizData from "@/quizData.js"
import { topologyInfo } from "@/quizData"

export default {
  // 传参：只有一级编号：还没答过题，该答哪一道？有二级或更多编号：答了这道题，该答哪一道？
  getNextQuestionId(currentId) {
    const idPerLevel = currentId.split('.')
    const targetLevel2Idx = idPerLevel.length > 1 ? Number(idPerLevel[1]) : 0
    const targetTopologyInfoLevel2 = topologyInfo[Number(idPerLevel[0]) - 1][targetLevel2Idx]
    if (Array.isArray(targetTopologyInfoLevel2)) {
      return targetTopologyInfoLevel2[Math.floor(Math.random() * targetTopologyInfoLevel2.length)]
    } else if (typeof targetTopologyInfoLevel2 === 'string') {
      return targetTopologyInfoLevel2
    } else {
      return '' //没题可答了
    }
  },
  getRemainingQuestionNumber(currentId) {
    const idPerLevel = currentId.split('.')
    if (idPerLevel.length === 1) {
      return topologyInfo[Number(idPerLevel[0]) - 1].length
    } else {
      return topologyInfo[Number(idPerLevel[0]) - 1].length - idPerLevel[1]
    }
  }
}
