<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>{{ role.role }} <small v-if="role.permissions?.isAdmin">(Admin)</small></p>
      <PencilIcon class="w-5 h-5 p-1 box-content cursor-pointer" @click="openUpdateModal" />
    </div>
  </div>
</template>

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

<script lang="ts">
export default defineComponent({
  props: {
    role: { type: Object as PropType<RoleViewModel>, default: {} },
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {
    ...mapActions(useModalStore, ["openModal"]),
    openUpdateModal() {
      this.openModal(
        markRaw(defineAsyncComponent(() => import("@/components/admin/user/role/UpdateRoleModal.vue"))),
        this.role.id
      );
    },
  },
});
</script>
