"use client" import { useState } from "react" import { ArrowLeft, Download, Pencil, Sparkles, Star, Trash2, Mail, Phone, Building2, MapPin, Cake, FileText, MessageSquare, Video, } from "lucide-react" import { Button } from "@/components/ui/button" import { useContactsStore } from "@/lib/contacts/contacts-store" import { useContactsList } from "@/lib/contacts/use-contacts-list" import { useDeleteContact } from "@/lib/api/hooks/use-contact-mutations" import { ContactAvatar } from "@/components/gmail/contacts/contact-avatar" import { fullContactDisplayName } from "@/lib/contacts/types" import { useNavStore } from "@/lib/stores/nav-store" import { downloadContactVCard } from "@/lib/contacts/export-contacts" import { CONTACTS_HEADING_TEXT, CONTACTS_MUTED_TEXT, CONTACTS_PAGE_ICON_BTN_CLASS, CONTACTS_PAGE_TAG_CLASS, CONTACTS_PANEL_DIVIDER_CLASS, CONTACTS_PANEL_MUTED_ICON_CLASS, CONTACTS_PANEL_PRIMARY_ACTION_CLASS, CONTACTS_PANEL_SECONDARY_ICON_BTN_CLASS, } from "@/lib/contacts-chrome-classes" import { cn } from "@/lib/utils" import { useLLMSettings } from "@/lib/api/hooks/use-contact-discovery" import { isLLMConfigured } from "@/lib/contacts/llm-settings-utils" import { ContactImproveDialog } from "@/components/gmail/contacts-page/contact-improve-dialog" const FRENCH_MONTHS = [ "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre", ] function formatBirthday(b: { day?: number; month?: number; year?: number }): string { const parts: string[] = [] if (b.day) parts.push(String(b.day)) if (b.month) parts.push(FRENCH_MONTHS[b.month - 1] ?? "") if (b.year) parts.push(String(b.year)) return parts.join(" ") } interface ContactDetailPageProps { contactId: string onBack: () => void onEdit: (id: string) => void } export function ContactDetailPage({ contactId, onBack, onEdit }: ContactDetailPageProps) { const { contacts } = useContactsList() const softDeleteContact = useContactsStore((s) => s.softDeleteContact) const deleteContactMutation = useDeleteContact() const labelRows = useNavStore((s) => s.labelRows) const { data: llmSettings } = useLLMSettings() const [improveOpen, setImproveOpen] = useState(false) const contact = contacts.find((c) => c.id === contactId) const llmReady = isLLMConfigured(llmSettings) if (!contact) { return (
Contact introuvable
) } const displayName = fullContactDisplayName(contact) const name = displayName || contact.emails[0]?.value || contact.phones[0]?.value || "?" const primaryEmail = contact.emails[0]?.value function handleDelete() { if (contact) softDeleteContact(contact, "Supprimé manuellement") deleteContactMutation.mutate({ path: contactId }) onBack() } return (

{name}

{contact.company && (

{contact.jobTitle ? `${contact.jobTitle} — ` : ""} {contact.company}

)} {contact.labels && contact.labels.length > 0 && (
{contact.labels.map((labelId) => { const row = labelRows.find((r) => r.id === labelId) return row ? ( {row.label} ) : null })}
)}
{primaryEmail && (
)}
{contact.emails.length > 0 && ( }> {contact.emails.map((e, i) => (

{e.value}

{e.label}

))}
)} {contact.phones.length > 0 && ( }> {contact.phones.map((p, i) => (

{p.value}

{p.label}

))}
)} {contact.company && ( }>

{contact.company}

{contact.department && (

{contact.department}

)} {contact.jobTitle && (

{contact.jobTitle}

)}
)} {contact.addresses && contact.addresses.length > 0 && ( }> {contact.addresses.map((addr, i) => (

{[addr.street, [addr.postalCode, addr.city].filter(Boolean).join(" "), addr.region, addr.country] .filter(Boolean) .join(", ")}

{addr.label}

))}
)} {contact.birthday && (contact.birthday.day || contact.birthday.month) && ( }>

{formatBirthday(contact.birthday)}

)} {contact.notes && ( }>

{contact.notes}

)}
) } function DetailRow({ icon, children }: { icon: React.ReactNode; children: React.ReactNode }) { return (
{icon}
{children}
) }