<script setup lang="ts">
import { useCurrentCourseSession } from "@/composables";
import AssignmentDetails from "@/pages/cockpit/assignmentsPage/AssignmentDetails.vue";
import * as log from "loglevel";
import { computed, onMounted } from "vue";
import { useUserStore } from "@/stores/user";
import { useLearningPathStore } from "@/stores/learningPath";
import { calcLearningContentAssignments } from "@/services/assignmentService";

const props = defineProps<{
  courseSlug: string;
  assignmentId: string;
}>();

log.debug("AssignmentsPage created", props.courseSlug);

const courseSession = useCurrentCourseSession();
const userStore = useUserStore();
const learningPathStore = useLearningPathStore();

onMounted(async () => {
  log.debug("AssignmentsPage mounted");
});

const learningContentAssignment = computed(() => {
  return calcLearningContentAssignments(
    learningPathStore.learningPathForUser(courseSession.value.course.slug, userStore.id)
  ).filter((lc) => lc.id === props.assignmentId)[0];
});
</script>

<template>
  <div class="bg-gray-200">
    <div class="container-large">
      <nav class="py-4 pb-4">
        <router-link
          class="btn-text inline-flex items-center pl-0"
          :to="`/course/${props.courseSlug}/cockpit`"
        >
          <it-icon-arrow-left />
          <span>{{ $t("general.back") }}</span>
        </router-link>
      </nav>
      <main>
        <div class="bg-white p-6">
          <AssignmentDetails
            v-if="learningContentAssignment"
            :course-session="courseSession"
            :learning-content-assignment="learningContentAssignment"
          />
        </div>
      </main>
    </div>
  </div>
</template>

<style scoped></style>
