<script setup lang="ts">
import { computed } from 'vue';
import { RowDeleteAction, RowEditAction } from '@/components/button';
import { useCan } from '@/composables/useCan';
import type { CashTransactionListItem } from '@/types/cash';
import { destroy } from '@/routes/admin/finance/cash/transactions';

const props = defineProps<{
    transaction: CashTransactionListItem;
}>();

const emit = defineEmits<{
    edit: [transaction: CashTransactionListItem];
}>();

const { can } = useCan();

const showActions = computed(() => props.transaction.reference_type === null);
</script>

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