<script setup lang="ts">
import { Link } from '@inertiajs/vue3';
import { History } from '@lucide/vue';
import { Button } from '@/components/ui/button';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';

defineProps<{
    href?: string;
    tooltip?: string;
    disabled?: boolean;
}>();

const emit = defineEmits<{
    click: [];
}>();
</script>

<template>
    <Tooltip>
        <TooltipTrigger as-child>
            <Button variant="ghost" size="icon" class="size-8" :disabled="disabled" :as-child="!!href && !disabled"
                @click="!href && !disabled && emit('click')">
                <Link v-if="href && !disabled" :href="href">
                    <History class="size-4" />
                    <span class="sr-only">{{ tooltip || 'Riwayat Stok' }}</span>
                </Link>
                <template v-else>
                    <History class="size-4" />
                    <span class="sr-only">{{ tooltip || 'Riwayat Stok' }}</span>
                </template>
            </Button>
        </TooltipTrigger>
        <TooltipContent>{{ tooltip || 'Riwayat Stok' }}</TooltipContent>
    </Tooltip>
</template>
