<script setup lang="ts">
import { RowDeleteAction, RowEditAction } from '@/components/button';
import OwnerVerificationRowActions from '@/components/owner-verification/OwnerVerificationRowActions.vue';
import { useCan } from '@/composables/useCan';
import { edit, destroy } from '@/routes/admin/manage/purchases';
import type { PurchaseListItem } from '@/types/purchase';

defineProps<{
    purchase: PurchaseListItem;
}>();

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

<template>
    <div class="flex items-center justify-end gap-1">
        <OwnerVerificationRowActions v-if="purchase.has_pending_request && purchase.pending_request_id" type="request"
            :id="purchase.pending_request_id" />

        <RowEditAction v-if="can('purchases.update')" :href="edit.url(purchase.id)"
            :disabled="purchase.has_pending_request"
            :tooltip="purchase.has_pending_request ? 'Menunggu verifikasi owner' : 'Ubah'" />
        <RowDeleteAction v-if="can('purchases.delete')" :action-url="destroy.url(purchase.id)"
            :disabled="purchase.has_pending_request"
            :tooltip="purchase.has_pending_request ? 'Menunggu verifikasi owner' : 'Hapus'" title="Hapus belanja?"
            :description="`Pengajuan hapus belanja ${purchase.total_formatted} dari ${purchase.supplier?.name ?? purchase.supplier_name} akan dikirim ke owner untuk verifikasi.`"
            error-message="Gagal mengajukan penghapusan belanja." />
    </div>
</template>
