<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 justify-between items-center">
      <p>{{ invite.firstname }} {{ invite.lastname }}</p>
      <div class="flex flex-row">
        <div v-if="can('delete', 'user', 'user')" @click="triggerDeleteInvite">
          <TrashIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
        </div>
      </div>
    </div>
    <div class="flex flex-col p-2">
      <div class="flex flex-row gap-2">
        <p class="min-w-16">Benutzer:</p>
        <p class="grow overflow-hidden">{{ invite.username }}</p>
      </div>
      <div class="flex flex-row gap-2">
        <p class="min-w-16">Mail:</p>
        <p class="grow overflow-hidden">{{ invite.mail }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineComponent, type PropType } from "vue";
import { mapState, mapActions } from "pinia";
import type { InviteViewModel } from "@/viewmodels/admin/user/invite.models";
import { PencilIcon, UserGroupIcon, WrenchScrewdriverIcon, TrashIcon } from "@heroicons/vue/24/outline";
import { useAbilityStore } from "@/stores/ability";
import { useInviteStore } from "@/stores/admin/user/invite";
</script>

<script lang="ts">
export default defineComponent({
  props: {
    invite: { type: Object as PropType<InviteViewModel>, default: {} },
  },
  computed: {
    ...mapState(useAbilityStore, ["can"]),
  },
  methods: {
    ...mapActions(useInviteStore, ["deleteInvite"]),
    triggerDeleteInvite() {
      this.deleteInvite(this.invite.mail);
    },
  },
});
</script>
