<script setup lang="ts">
import { useCourseData, useCurrentCourseSession } from "@/composables";
import AssignmentDetails from "@/pages/cockpit/assignmentsPage/AssignmentDetails.vue";
import * as log from "loglevel";
import { computed, onMounted } from "vue";
import type { LearningContentAssignment, LearningContentEdoniqTest } from "@/types";

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

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

const courseSession = useCurrentCourseSession();

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

const lpQueryResult = useCourseData(props.courseSlug);

const learningContentAssignment = computed(() => {
  return lpQueryResult.findLearningContent(props.assignmentId);
});
</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="learningContentAssignment as (LearningContentAssignment | LearningContentEdoniqTest)"
          />
        </div>
      </main>
    </div>
  </div>
</template>

<style scoped></style>
