import{X as i}from"./app-C3pBWUn1.js";const a=i("exam",{state:()=>({token:"",currentQuestion:[],examSession:{},isExamSubmitted:!1,currentTimer:0,answers:[],timerInterval:null,score:0,perQeustionTime:0,errorMessage:"",sessionClosed:!1,isResetTimer:!1}),getters:{formattedTime(e){const t=Math.floor(e.currentTimer/60),s=e.currentTimer%60;return`${t}:${s<10?"0":""}${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.perQeustionTime},async fetchQuestions(e,t){this.token=t,this.sessionClosed=!1;try{const s=await axios.get(`/exam/start/${e}`,{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${t}`}});this.currentQuestion=s.data.data.questions,this.examSession=s.data.data.examSession,this.perQeustionTime=this.examSession.exam_duration,this.isResetTimer&&this.resetTimer()}catch(s){this.errorMessage=s.response.data.message,this.sessionClosed=!0}this.startTimer()},async submitQuiz(){this.sessionClosed=!1;try{const e=await axios.post(`/exam/submit/${this.examSession.id}`,{answers:this.answers},{headers:{"Content-Type":"application/json",Accept:"application/json",Authorization:`Bearer ${this.token}`}});this.score=e.data.data.obtained_mark,this.isExamSubmitted=!0,this.stopTimer(),this.answers=[],this.currentQuestion=0,this.currentTimer=0}catch(e){this.errorMessage=e.response.data.message,this.sessionClosed=!0}}},persist:!0});export{a as u};
