<script setup lang="ts">
import { RowDeleteAction, RowEditAction, RowSubmitAction, RowApproveAction, RowRejectAction } from '@/components/button';
import { useCan } from '@/composables/useCan';
import { destroy } from '@/routes/admin/manage/stok-opnames';
import type { StokOpnameListItem } from '@/types/stok-opname';

defineProps<{
    stokOpname: StokOpnameListItem;
}>();

const emit = defineEmits<{
    edit: [];
    submit: [];
    verify: [];
    reject: [];
}>();

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

<template>
    <div class="flex items-center justify-end gap-1">
        <RowSubmitAction
            v-if="can('stok_opnames.submit') && (stokOpname.status === 'draft' || stokOpname.status === 'rejected')"
            tooltip="Ajukan Verifikasi"
            @click="emit('submit')"
        />

        <RowApproveAction
            v-if="can('stok_opnames.verify') && stokOpname.status === 'pending'"
            tooltip="Verifikasi"
            @click="emit('verify')"
        />

        <RowRejectAction
            v-if="can('stok_opnames.verify') && stokOpname.status === 'pending'"
            tooltip="Tolak"
            @click="emit('reject')"
        />

        <RowEditAction
            v-if="can('stok_opnames.update') && (stokOpname.status === 'draft' || stokOpname.status === 'rejected')"
            @click="emit('edit')"
        />
        <RowDeleteAction
            v-if="can('stok_opnames.delete') && (stokOpname.status === 'draft' || stokOpname.status === 'rejected')"
            :action-url="destroy.url(stokOpname.id)"
            title="Hapus stok opname?"
            description="Data stok opname ini akan dihapus permanen."
        />
    </div>
</template>
