<template>
  <div class="flex flex-col h-fit w-full border border-primary rounded-md">
    <div class="bg-primary p-2 text-white flex flex-row gap-2 justify-between items-center">
      <p class="grow">
        {{ membership.start }} bis {{ membership.end ?? "heute" }}:
        {{ membership.status }}
      </p>
      <PencilIcon class="w-5 h-5 cursor-pointer" @click="openEditModal" />
      <TrashIcon class="w-5 h-5 cursor-pointer" @click="openDeleteModal" />
    </div>
    <div v-if="membership.terminationReason || membership.internalId" class="p-2">
      <p v-if="membership.internalId">Interne ID: {{ membership.internalId }}</p>
      <p v-if="membership.terminationReason">beendet, weil: {{ membership.terminationReason }}</p>
    </div>
  </div>
</template>

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

<script lang="ts">
export default defineComponent({
  props: {
    membership: {
      type: Object as PropType<MembershipViewModel>,
      default: {},
    },
  },
  methods: {
    ...mapActions(useModalStore, ["openModal"]),
    openEditModal() {
      this.openModal(
        markRaw(defineAsyncComponent(() => import("@/components/admin/club/member/MembershipEditModal.vue"))),
        this.membership.id
      );
    },
    openDeleteModal() {
      this.openModal(
        markRaw(defineAsyncComponent(() => import("@/components/admin/club/member/MembershipDeleteModal.vue"))),
        this.membership.id
      );
    },
  },
});
</script>
