<script setup lang="ts">
definePageMeta({
  layout: "exam",
});

const examStore = useExamStore();

const points = ref<number>();

if (!examStore.end) {
  examStore.resetExam();
  setTimeout(() => {
    return navigateTo("/");
  }, 5000);
} else {
  let sum = 0;
  examStore.result.basic.forEach((a) => {
    if (a.chosen_is_correct) {
      sum += a.liczba_pkt ?? 0;
    }
  });
  examStore.result.advanced.forEach((a) => {
    if (a.chosen_is_correct) {
      sum += a.liczba_pkt ?? 0;
    }
  });
  points.value = sum;
}
</script>

<template>
  <div class="text-4xl">
    <div v-if="!examStore.end">Exam not finished, redirecting...</div>
    <div v-else>
      Result: {{ points }} / 74
      <br />
      {{ examStore.result }}
    </div>
  </div>
</template>
