<script setup lang="ts">
import CompetenceDetail from "@/pages/competence/ActionCompetenceDetail.vue";
import * as log from "loglevel";
import { ref } from "vue";
import { useCourseDataWithCompletion } from "@/composables";

log.debug("CompetenceListPage created");

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

const courseData = useCourseDataWithCompletion(props.courseSlug);

const isOpenAll = ref(false);

function toggleOpen() {
  log.debug("toggleOpen");
  isOpenAll.value = !isOpenAll.value;
}
</script>

<template>
  <div class="container-large">
    <h2 class="py-4">{{ $t("a.Handlungskompetenzen") }}</h2>

    <div class="flex flex-col justify-between gap-4 py-8 lg:flex-row">
      <div class="text-xl lg:w-3/4">
        {{ $t("competence.listPageDescription") }}
      </div>
      <div class="lg:whitespace-nowrap">
        <button class="link" @click="toggleOpen()">
          <span v-if="isOpenAll">
            {{ $t("a.Alle zuklappen") }}
          </span>
          <span v-else>
            {{ $t("a.Alle aufklappen") }}
          </span>
        </button>
      </div>
    </div>

    <ul v-if="courseData.actionCompetences.value?.length">
      <li
        v-for="competence in courseData.actionCompetences.value"
        :key="competence.id"
        class="mb-8 bg-white px-8 pt-6"
      >
        <CompetenceDetail
          :competence="competence"
          :course-slug="props.courseSlug"
          :all-open="isOpenAll"
        ></CompetenceDetail>
      </li>
    </ul>
  </div>
</template>

<style scoped></style>
