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

log.debug("CompetenceListPage created");

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

const competenceStore = useCompetenceStore();

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="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="competenceStore.competenceProfilePage()">
      <li
        v-for="competence in competenceStore.competences()"
        :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>
