<script setup lang="ts">
import { RowDeleteAction, RowEditAction } from '@/components/button';
import OwnerVerificationRowActions from '@/components/owner-verification/OwnerVerificationRowActions.vue';
import { useCan } from '@/composables/useCan';
import type { RawMaterialListItem } from '@/types/raw-material';
import { edit, destroy } from '@/routes/admin/master/raw_materials';

defineProps<{
    material: RawMaterialListItem;
}>();

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

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

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