<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/restocks';
import type { RestockListItem } from '@/types/restock';

defineProps<{
    restock: RestockListItem;
}>();

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

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

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