<template>
  <div
    class="
      tw-flex tw-gap-4 tw-justify-between tw-items-center
      header-container
      tw-px-1
    "
    v-if="store.setting"
  >
    <div>
      {{
        `${store.setting.subject.code ?? ""}-${
          store.setting.subject.name ?? ""
        }`
      }}
    </div>
    <div class="tw-flex tw-gap-1">
      <div>
        编号<span class="highlight-text">{{
          store.currentTask?.secretNumber
        }}</span>
      </div>
    </div>
    <ul v-if="!isSingleStudent" class="tw-flex tw-gap-2 tw-mb-0">
      <li>
        待复核<span class="highlight-text">{{ store.status.totalCount }}</span>
      </li>
    </ul>
    <ZoomPaper :store="store" />
    <div class="tw-flex tw-place-items-center">
      <UserOutlined class="icon-font icon-with-text" />{{
        store.setting.userName
      }}
    </div>
    <div
      class="tw-flex tw-place-items-center tw-cursor-pointer"
      @click="closeWindow"
    >
      <PoweroffOutlined class="icon-font icon-with-text" />关闭
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { store } from "@/features/mark/store";
import { UserOutlined, PoweroffOutlined } from "@ant-design/icons-vue";
import { useRoute } from "vue-router";
import { clearInspectedTask } from "@/api/libraryInspectPage";
import ZoomPaper from "@/components/ZoomPaper.vue";

const route = useRoute();
let isSingleStudent = ref(false);
isSingleStudent.value = !!route.query.studentId;
const { subjectCode, groupNumber } = route.query as {
  subjectCode: string;
  groupNumber: string;
};

async function updateClearTask() {
  await clearInspectedTask(subjectCode, groupNumber);
}

const closeWindow = async () => {
  await updateClearTask();
  window.close();
};

onMounted(() => {
  // 不确定是否一定能在关闭页面时调用
  window.addEventListener("beforeunload", () => {
    updateClearTask();
  });
});
</script>

<style scoped>
.header-container {
  position: relative;
  font-size: 16px;
  height: 40px;

  background-color: #5d6d7d;
  color: white;
}
.highlight-text {
  color: #ffe400;
}
.icon-font {
  display: block;
}
.icon-with-text {
  font-size: 18px;
  line-height: 18px;
}
</style>
