<template>
  <div class="flex flex-col h-fit w-full border border-primary rounded-md overflow-hidden">
    <div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
      <div class="flex flex-row items-center gap-2">
        <div class="rounded-md h-5 w-5" :style="'background-color:' + calendarType.color">
          <EyeIcon v-if="calendarType.nscdr" class="w-5 h-5" />
        </div>
        <p>{{ calendarType.type }}</p>
        <small v-if="calendarType.passphrase">(passwortgeschützt)</small>
        <small v-if="calendarType.nscdr">(standard-Auslieferung)</small>
      </div>
      <div class="flex flex-row">
        <RouterLink
          v-if="can('update', 'settings', 'calendar_type')"
          :to="{ name: 'admin-settings-calendar_type-edit', params: { id: calendarType.id } }"
        >
          <PencilIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
        </RouterLink>
        <div v-if="can('delete', 'settings', 'calendar_type')" @click="openDeleteModal">
          <TrashIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineComponent, defineAsyncComponent, markRaw, type PropType } from "vue";
import { mapState, mapActions } from "pinia";
import { PencilIcon, TrashIcon, EyeIcon } from "@heroicons/vue/24/outline";
import { useAbilityStore } from "@/stores/ability";
import { useModalStore } from "@/stores/modal";
import type { CalendarTypeViewModel } from "@/viewmodels/admin/calendarType.models";
</script>

<script lang="ts">
export default defineComponent({
  props: {
    calendarType: { type: Object as PropType<CalendarTypeViewModel>, default: {} },
  },
  computed: {
    ...mapState(useAbilityStore, ["can"]),
  },
  methods: {
    ...mapActions(useModalStore, ["openModal"]),
    openDeleteModal() {
      this.openModal(
        markRaw(
          defineAsyncComponent(() => import("@/components/admin/settings/calendarType/DeleteCalendarTypeModal.vue"))
        ),
        this.calendarType.id
      );
    },
  },
});
</script>
