<script setup lang="ts">
import { computed } from 'vue';
import { RowDeleteAction, RowEditAction } from '@/components/button';
import { useCan } from '@/composables/useCan';
import type { RoleListItem } from './columns';
import { edit, destroy } from '@/routes/admin/system/roles';

const props = defineProps<{
    role: RoleListItem;
}>();

const { can } = useCan();

const isSystemRole = computed(() => {
    return ['developer', 'owner', 'admin-toko', 'admin-bahan-baku', 'direktur', 'marketing', 'cashier', 'non-operator'].includes(props.role.name);
});
</script>

<template>
    <div class="flex items-center justify-end gap-1">
        <RowEditAction v-if="can('roles.update')" :href="edit.url(role.id)" />
        <RowDeleteAction v-if="can('roles.delete') && !isSystemRole" :action-url="destroy.url(role.id)" title="Hapus role?"
            :description="`Role ${role.name} akan dihapus secara permanen. Tindakan ini tidak dapat dibatalkan.`"
            error-message="Gagal menghapus role." />
    </div>
</template>
