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

defineProps<{
    href?: string;
    tooltip?: string;
    tooltipClass?: string;
    buttonClass?: string;
}>();

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

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