<script setup lang="ts">
import { RowDeleteAction, RowEditAction } from '@/components/button';
import { useCan } from '@/composables/useCan';
import type { ExpenseListItem } from '@/types/expense';
import { destroy } from '@/routes/admin/finance/expenses';

defineProps<{
    expense: ExpenseListItem;
}>();

const emit = defineEmits<{
    edit: [expense: ExpenseListItem];
}>();

const { can } = useCan();
</script>

<template>
    <div class="flex items-center justify-end gap-1">
        <RowEditAction v-if="can('expenses.update')" @click="emit('edit', expense)" />
        <RowDeleteAction v-if="can('expenses.delete')" :action-url="destroy.url(expense.id)" title="Hapus pengeluaran?"
            :description="`Pengeluaran ${expense.amount_formatted} akan dihapus. Saldo kas akan disesuaikan.`"
            :on-error="(errors) => errors.amount || errors.transaction || 'Gagal menghapus pengeluaran.'" />
    </div>
</template>
