<template>
  <ie-page bg-color="#F6F8FA">
    <ie-navbar title="" bg-color="transparent" :placeholder="false" />
    <view class="relative">
      <ie-image :is-oss="true" src="/study-bg9.png" custom-class="w-full h-[544rpx] absolute top-0 left-0 z-0" />
      <ie-image :is-oss="true" src="/study-bg10.png" custom-class="w-312 h-198 absolute top-75 right-32 z-1"
        mode="aspectFill" />
      <view class="relative z-2 mx-30">
        <view class="pt-126 ml-55">
          <ie-image :is-oss="true" src="/study-title5.png" customClass="w-264 h-60" />
        </view>
        <view class="mt-65 bg-white rounded-15 px-40 pt-50 pb-40">
          <view class="text-36 text-fore-title text-center font-bold">{{ universityInfo.universityName }}</view>
          <view class="mt-26 text-32 text-fore-title text-center font-bold">模考须知</view>
          <view class="mt-66">
            <view class="flex items-center justify-between">
              <text class="text-28 text-fore-light">所考专业</text>
              <text class="text-28 text-fore-title">{{ universityInfo.majorName }}</text>
            </view>
            <view class="mt-40 flex items-center justify-between">
              <text class="text-28 text-fore-light">考生类型</text>
              <text class="text-28 text-fore-title">
                <ie-dict :dict-name="EnumDictName.EXAM_TYPE" :dict-value="userStore.getExamType || '--'" />
              </text>
            </view>
            <view class="mt-40 flex items-center justify-between">
              <text class="text-28 text-fore-light">考试类型</text>
              <text class="text-28 text-fore-title">{{ subjectInfo.subject }}</text>
            </view>
            <view class="mt-40 flex items-center justify-between">
              <text class="text-28 text-fore-light">考试标准</text>
              <text class="text-28 text-fore-title">{{ examTime }}分钟，满分{{ totalScore }}分</text>
            </view>
            <view class="mt-40 flex items-center justify-between">
              <text class="text-28 text-fore-light">考试题型</text>
              <text class="text-28 text-fore-title">单选、多选、判断</text>
            </view>
          </view>
          <view class="mt-36 rounded-15 bg-back px-40 py-36 flex">
            <view class="flex-1 text-center">
              <view class="text-40 text-fore-title font-bold">{{ questions.length }}</view>
              <view class="mt-10 text-28 text-fore-light">题量</view>
            </view>
            <view class="flex-1 text-center">
              <view class="text-40 text-fore-title font-bold">{{ totalScore }}</view>
              <view class="mt-10 text-28 text-fore-light">总分</view>
            </view>
          </view>
          <ie-button type="primary" custom-class="mt-44" :disabled="!isReady" @click="handleStartTest">开始考试</ie-button>
        </view>
      </view>
    </view>
  </ie-page>
</template>

<script lang="ts" setup>
import { useTransferPage } from '@/hooks/useTransferPage';
import { getOpenExaminee, getPaper } from '@/api/modules/study';
import { useUserStore } from '@/store/userStore';
import { EnumDictName } from '@/common/enum';
import { Study } from '@/types';
const { prevData, transferTo } = useTransferPage();
const userStore = useUserStore();

const isReady = ref(false);
const totalScore = ref(0);
const examTime = ref(0);
const questions = ref<Study.Question[]>([]);
const universityInfo = computed(() => {
  return prevData.value.universityInfo;
});
const subjectInfo = computed(() => {
  return prevData.value.subjectInfo;
});
const handleStartTest = () => {
  transferTo('/pagesStudy/pages/simulation-analysis/simulation-analysis')
}
const loadData = async () => {
  uni.$ie.showLoading('AI智能出卷中...');
  const { data } = await getOpenExaminee({
    paperType: 'Simulated',
    subjectId: subjectInfo.value.subjectId,
    directed: true
  });
  if (!data) {
    uni.$ie.hideLoading();
    return;
  }
  const { examineeId, paperId } = data;
  const { data: paperData } = await getPaper({ type: 'Simulated', id: paperId });
  if (paperData) {
    console.log(paperData)
    isReady.value = true;
  }
  uni.$ie.hideLoading();
}
onLoad(() => {
  loadData();
});
</script>

<style lang="scss" scoped></style>
