<script setup lang="ts">
import { Link } from '@inertiajs/vue3';
import { Eye } 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">
                    <Eye class="size-4" />
                    <span class="sr-only">{{ tooltip || 'Detail' }}</span>
                </Link>
                <template v-else>
                    <Eye class="size-4" />
                    <span class="sr-only">{{ tooltip || 'Detail' }}</span>
                </template>
            </Button>
        </TooltipTrigger>
        <TooltipContent>{{ tooltip || 'Detail' }}</TooltipContent>
    </Tooltip>
</template>
