<template>
  <div class="title cl">
    <span class="y"><router-link to="/home">返回考试主页</router-link></span>
    <h2>数据同步</h2>
  </div>
  <div class="data">
    <p>
      本地已下载考生数量：<b id="student-count">{{ studentCount }}</b>
    </p>
    <p>
      上次下载完成时间：<b id="last-time">{{ lastSyncTime }}</b>
    </p>
    <div class="btn">
      <router-link to="/sync-run"><span>开始同步数据</span></router-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { store } from "@/store";
import { onMounted, ref } from "vue";

const syncId = store.env.server.host + "_" + store.env.exam.id;
const lastSync = store.syncTime.find((v) => v.id === syncId);
const lastSyncTime = lastSync ? lastSync.time : "无";

let studentCount = ref(0);
onMounted(async () => {
  const studentCountRes = await window.electron.queryStudentCount(
    JSON.parse(JSON.stringify(store))
  );
  // console.log(studentCountRes);
  studentCount.value = studentCountRes;
});
</script>
