"use client"; import { Copy } from "lucide-react"; import { toast } from "sonner"; import { useI18n } from "@/i18n/i18n-context"; import { copyToClipboard } from "@/lib/clipboard"; import { cn } from "@/lib/utils"; interface CopyableIdProps { value: string | null | undefined; label?: string; className?: string; valueClassName?: string; copyLabel?: string; } /** Compact, overflow-safe identifier with full-value tooltip and copy action. */ export function CopyableId({ value, label = "ID", className, valueClassName, copyLabel, }: CopyableIdProps) { const { t } = useI18n(); const copyable = value !== null && value !== undefined && value !== ""; const displayValue = copyable ? value : "-"; const accessibleLabel = copyLabel || label || "ID"; async function handleCopy(event: React.MouseEvent) { event.preventDefault(); event.stopPropagation(); try { await copyToClipboard(displayValue); toast.success(t("common.copied")); } catch { toast.error(t("common.copyFailed")); } } return (
{label ? ( {label}: ) : null} {displayValue} {copyable ? ( ) : null}
); }