<template>
    <mx-paper>
        <template #bottom>
            <mx-paper-progress/>
            <mx-question-statistic class="!items-center"/>
            <mx-paper-completion/>
        </template>
    </mx-paper>
</template>

<script setup>
import {ref, onMounted} from 'vue';
import mxConst from "@/common/mxConst";
import {openExamineePaper} from "@/api/webApi/studentEvaluating.js"
import {useTransfer} from "@/hooks/useTransfer";
import {useProvidePaperService} from "@/components/mx-paper/usePaperInjection";
import {useProvideQuestionService} from "@/components/mx-question/useQuestionInjection";
import {useProvidePaperNavigationService} from "@/components/mx-paper/usePaperNavigationServiceInjection";
import MxQuestionStatistic from "@/components/mx-question/components/mx-question-statistic.vue";
import MxPaperCompletion from "@/components/mx-paper/components/mx-paper-completion.vue";
import MxPaperProgress from "@/components/mx-paper/components/mx-paper-progress.vue";

const {prevData, transferTo} = useTransfer()
const paperData = ref({name: '心理健康测评'})
const paperService = useProvidePaperService(paperData)
const questionService = useProvideQuestionService(paperService, 20, false)
useProvidePaperNavigationService(paperService, questionService)

onMounted(async () => {
    const payload = {
        ...prevData.value,
        examineeType: mxConst.enum.mentalHealthTestType
    }
    uni.showLoading()
    try {
        const res = await openExamineePaper(payload)
        paperData.value = res.data
    } finally {
        uni.hideLoading()
    }
})

paperService.onAnswerComplete(async () => {
    // 心理测评不需要阅卷过程，直接进入报告页
    const url = '/pagesOther/pages/test-center/mental-health/report'
    const params = {
        testType: prevData.value.testType,
        examineeId: paperData.value.examineeId
    }
    transferTo({url, params, type: 'redirect'})
})
</script>

<style>

</style>
