import{Y as s}from"./app-L4cdeQDO.js";const a=s("quiz",{state:()=>({currentQuestion:1,totalQuestion:0,isResetTimer:!1,authToken:"",quizData:{},quizSession:{},answers:{},currentTimer:0,timerManager:0,isQuizSubmitted:!1,score:0,timerInterval:null}),getters:{formattedTime(t){const i=Math.floor(t.currentTimer/60),e=t.currentTimer%60;return i>0?`${i}m ${e}s`:`${e}s`}},actions:{startTimer(){this.stopTimer(),this.timerInterval=setInterval(()=>{this.currentTimer>0?this.currentTimer--:this.stopTimer()},1e3)},stopTimer(){this.timerInterval&&(clearInterval(this.timerInterval),this.timerInterval=null)},resetTimer(){this.isResetTimer=!1,this.stopTimer(),this.currentTimer=this.timerManager},resetQuizState(){this.currentQuestion=1,this.currentTimer=0,this.timerManager=0,this.timerInterval=null,this.answers={}},async nextQuestion(){await axios.post(`/quiz/submit/${this.quizSession.id}`,{answer:this.answers},{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${this.authToken}`}}).then(t=>{t.data.data.question?(this.quizData=t.data.data.question,this.quizData.quizSession=t.data.data.quiz_session,this.quizData.timerManager=t.data.data.quiz_session.quiz_duration,this.currentQuestion++,this.resetTimer(),this.startTimer()):(this.quizData.quizSession=t.data.data.quiz_session,this.currentQuestion=1,this.isQuizSubmitted=!0,this.score=this.quizData.quizSession.obtained_mark,this.currentTimer=0,this.timerManager=0,this.timerInterval=null,this.stopTimer(),this.resetQuizState()),this.answers={}}).catch(t=>{console.log(t)})}},persist:!0});export{a as u};
