/** * Contact links (phone, Telegram) for duty cards and day detail. * Ported from webapp/js/contactHtml.js buildContactLinksHtml. */ "use client"; import { useTranslation } from "@/i18n/use-translation"; import { formatPhoneDisplay } from "@/lib/phone-format"; import { openPhoneLink } from "@/lib/open-phone-link"; import { openTelegramProfile } from "@/lib/telegram-link"; import { triggerHapticLight } from "@/lib/telegram-haptic"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { Phone as PhoneIcon, Send as TelegramIcon } from "lucide-react"; export interface ContactLinksProps { phone?: string | null; username?: string | null; layout?: "inline" | "block"; showLabels?: boolean; /** Optional label for aria-label on links (e.g. duty holder name for "Call …", "Message … on Telegram"). */ contextLabel?: string; className?: string; } const linkClass = "text-accent hover:underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2"; /** * Renders phone (tel:) and Telegram (t.me) links. Used on flip card back and day detail. */ export function ContactLinks({ phone, username, layout = "inline", showLabels = true, contextLabel, className, }: ContactLinksProps) { const { t } = useTranslation(); const hasPhone = Boolean(phone && String(phone).trim()); const rawUsername = username && String(username).trim(); const cleanUsername = rawUsername ? rawUsername.replace(/^@+/, "") : ""; const hasUsername = Boolean(cleanUsername); if (!hasPhone && !hasUsername) return null; const handlePhoneClick = (e: React.MouseEvent) => { e.preventDefault(); openPhoneLink(phone ?? undefined); triggerHapticLight(); }; const ariaCall = contextLabel ? t("contact.aria_call", { name: contextLabel }) : t("contact.phone"); const ariaTelegram = contextLabel ? t("contact.aria_telegram", { name: contextLabel }) : t("contact.telegram"); if (layout === "block") { return (
{hasPhone && ( )} {hasUsername && ( )}
); } const parts: React.ReactNode[] = []; if (hasPhone) { const displayPhone = formatPhoneDisplay(phone!); parts.push( showLabels ? ( {t("contact.phone")}:{" "} {displayPhone} ) : ( {displayPhone} ) ); } if (hasUsername) { const href = `https://t.me/${encodeURIComponent(cleanUsername)}`; const handleTelegramClick = (e: React.MouseEvent) => { e.preventDefault(); openTelegramProfile(cleanUsername); triggerHapticLight(); }; const link = ( @{cleanUsername} ); parts.push(showLabels ? {t("contact.telegram")}: {link} : link); } return (
{parts.map((p, i) => ( {i > 0 && ·} {p} ))}
); }