<template>
  <ie-page bg-color="#F6F8FA" :fix-height="true">
    <ie-navbar title="教材同步练习记录" />
    <view class="mt-20">
      <view v-for="(item, index) in historyList" :key="index"
        class="bg-white px-40 py-30 flex items-center sibling-border-top">
        <view class="flex-1">
          <view class="text-28">
            <text class=" text-fore-light">知识点：</text>
            <text class="text-fore-title">{{ item.paperName }}</text>
          </view>
          <view class="mt-10 text-28">
            <text class=" text-fore-light">完成时间：</text>
            <text class="text-fore-title">{{ item.endTime }}</text>
          </view>
        </view>
        <view class="text-24 text-white bg-primary w-fit px-40 py-12 rounded-full text-center"
          @click="handleViewHistory(item)">
          查看
        </view>
      </view>
    </view>
  </ie-page>
</template>
<script lang="ts" setup>
import { useNavbar } from '@/hooks/useNavbar';
import { useTransferPage } from '@/hooks/useTransferPage';
import { getTextbooksPracticeHistory } from '@/api/modules/study';
import { Study } from '@/types';
import { Transfer } from '@/types';
import { EnumPaperType } from '@/common/enum';
const { prevData, transferTo } = useTransferPage<{}, Transfer.PracticeResultPageOptions>();
const { baseStickyTop } = useNavbar();
const historyList = ref<Study.PracticeHistory[]>([]);
const handleViewHistory = (value: Study.PracticeHistory) => {
  transferTo('/pagesStudy/pages/knowledge-practice-detail/knowledge-practice-detail', {
    data: {
      paperType: EnumPaperType.COURSE,
      examineeId: value.examineeId,
      name: value.paperName,
      directed: value.directed === 1
    } as Transfer.PracticeResultPageOptions,
  });
}
const loadData = async () => {
  uni.$ie.showLoading();
  try {
    const { rows } = await getTextbooksPracticeHistory();
    historyList.value = rows.map(item => {
      return {
        ...item,
        endTime: uni.$uv.timeFormat(item.endTime, 'yyyy-mm-dd hh:MM:ss')
      } as Study.PracticeHistory;
    });
  } finally {
    uni.$ie.hideLoading();
  }
}
onLoad(() => {
  console.log(prevData.value)
  loadData();
});
</script>
<style lang="scss" scoped></style>