<script setup lang="ts">
import { RowDeleteAction, RowEditAction } from '@/components/button';
import { Button } from '@/components/ui/button';
import { useCan } from '@/composables/useCan';
import type { StokOpnameListItem } from '@/types/stok-opname';
import { Send, CheckCircle, XCircle } from '@lucide/vue';
import { destroy } from '@/routes/admin/manage/stok-opnames';

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

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

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

<template>
    <div class="flex items-center justify-end gap-1">
        <Button
            v-if="can('stok_opnames.submit') && (stokOpname.status === 'draft' || stokOpname.status === 'rejected')"
            variant="ghost"
            size="icon"
            class="size-8 text-blue-600"
            title="Ajukan Verifikasi"
            @click="emit('submit')"
        >
            <Send class="size-4" />
        </Button>

        <Button
            v-if="can('stok_opnames.verify') && stokOpname.status === 'pending'"
            variant="ghost"
            size="icon"
            class="size-8 text-green-600"
            title="Verifikasi"
            @click="emit('verify')"
        >
            <CheckCircle class="size-4" />
        </Button>

        <Button
            v-if="can('stok_opnames.verify') && stokOpname.status === 'pending'"
            variant="ghost"
            size="icon"
            class="size-8 text-red-600"
            title="Tolak"
            @click="emit('reject')"
        >
            <XCircle class="size-4" />
        </Button>

        <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>
