"use client"; import { useTranslations } from "next-intl"; import { ContextMenu, ContextMenuItem, ContextMenuSeparator, ContextMenuHeader, } from "@/components/ui/context-menu"; import { Eye, Pencil, Mail, Phone, ClipboardCopy, Download, Users, Trash2, Copy, Printer, } from "lucide-react"; import type { ContactCard } from "@/lib/jmap/types"; import { getContactPrimaryEmail } from "@/stores/contact-store"; import { exportContact } from "./contact-export"; import { printContact } from "./contact-print"; import { toast } from "@/stores/toast-store"; function getContactPrimaryPhone(contact: ContactCard): string { if (!contact.phones) return ""; return Object.values(contact.phones)[0]?.number || ""; } interface Position { x: number; y: number; } interface ContactContextMenuProps { contact: ContactCard; position: Position; isOpen: boolean; onClose: () => void; menuRef: React.RefObject; isMultiSelect?: boolean; selectedCount?: number; onOpen: () => void; onEdit: () => void; onDelete: () => void; onAddToGroup: () => void; onDuplicate?: () => void; onBatchExport?: () => void; onBatchAddToGroup?: () => void; onBatchDelete?: () => void; } export function ContactContextMenu({ contact, position, isOpen, onClose, menuRef, isMultiSelect = false, selectedCount = 1, onOpen, onEdit, onDelete, onAddToGroup, onDuplicate, onBatchExport, onBatchAddToGroup, onBatchDelete, }: ContactContextMenuProps) { const t = useTranslations("contacts"); const email = getContactPrimaryEmail(contact); const phone = getContactPrimaryPhone(contact); const showBatchActions = isMultiSelect && selectedCount > 1; const handle = (fn: () => void) => () => { fn(); onClose(); }; const handleSendEmail = () => { if (!email) return; window.location.href = `mailto:${email}`; }; const handleCall = () => { if (!phone) return; window.location.href = `tel:${phone}`; }; const handleCopy = async (value: string) => { if (!value) return; try { await navigator.clipboard.writeText(value); toast.success(t("detail.copied")); } catch { toast.error(t("detail.copy_failed")); } }; const handleExport = () => { exportContact(contact); toast.success(t("export.success", { count: 1 })); }; const handlePrint = () => { printContact(contact); }; if (showBatchActions) { return ( {t("bulk.selected", { count: selectedCount })} onBatchAddToGroup?.())} disabled={!onBatchAddToGroup} /> onBatchExport?.())} disabled={!onBatchExport} /> onBatchDelete?.())} disabled={!onBatchDelete} destructive /> ); } return ( {(email || phone) && } {email && ( )} {phone && ( )} {email && ( handleCopy(email))} /> )} {phone && ( handleCopy(phone))} /> )} {onDuplicate && ( )} ); }