"use client" import { useMemo } from "react" import { Pencil, Star, X, Mail, Phone, Building2, MapPin, Cake, FileText, MessageSquare, Video, } from "lucide-react" import { Button } from "@/components/ui/button" import { ScrollArea } from "@/components/ui/scroll-area" import { useContactsStore } from "@/lib/contacts/contacts-store" import { fullContactDisplayName } from "@/lib/contacts/types" import { avatarColor, senderInitial } from "@/lib/sender-display" import { emails as allEmails } from "@/lib/email-data" import { useComposeActions } from "@/lib/compose-context" import { useNavStore } from "@/lib/stores/nav-store" import { CONTACTS_HEADING_TEXT, CONTACTS_MUTED_TEXT, CONTACTS_PANEL_DIVIDER_CLASS, CONTACTS_PANEL_HEADER_COMPACT_CLASS, CONTACTS_PANEL_ICON_BTN_CLASS, CONTACTS_PANEL_MUTED_ICON_CLASS, CONTACTS_PANEL_PRIMARY_ACTION_CLASS, CONTACTS_PANEL_ROW_CLASS, CONTACTS_PANEL_SECONDARY_ICON_BTN_CLASS, CONTACTS_PANEL_SHELL_CLASS, CONTACTS_PANEL_TAG_CLASS, } from "@/lib/contacts-chrome-classes" import { cn } from "@/lib/utils" import { ContactsPanelLogo } from "./contacts-panel-logo" interface ContactDetailViewProps { contactId: string | null } 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(" ") } function formatEmailDate(iso: string): string { const d = new Date(iso) const now = new Date() const diffDays = Math.floor((now.getTime() - d.getTime()) / 86_400_000) if (diffDays === 0) return "Aujourd'hui" if (diffDays === 1) return "Hier" if (diffDays < 7) return `Il y a ${diffDays} jours` return d.toLocaleDateString("fr-FR", { day: "numeric", month: "short", year: "numeric" }) } export function ContactDetailView({ contactId }: ContactDetailViewProps) { const { contacts, setView, showContactsList, closePanel } = useContactsStore() const { openComposeWithInitial } = useComposeActions() const labelRows = useNavStore((s) => s.labelRows) const contact = contacts.find((c) => c.id === contactId) const recentInteractions = useMemo(() => { if (!contact) return [] const contactEmails = new Set( contact.emails.map((e) => e.value.toLowerCase()).filter(Boolean) ) if (contactEmails.size === 0) return [] return allEmails .filter((email) => { const se = email.senderEmail?.toLowerCase() if (se && contactEmails.has(se)) return true const senderLower = email.sender.toLowerCase() return [...contactEmails].some((ce) => senderLower.includes(ce.split("@")[0] ?? "")) }) .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) .slice(0, 10) }, [contact]) if (!contact) { return (
{contact.jobTitle ? `${contact.jobTitle} — ` : ""} {contact.company}
)} {contact.labels && contact.labels.length > 0 && ({e.value}
{e.label}
{p.value}
{p.label}
{contact.company}
{contact.department && ({contact.department}
)} {contact.jobTitle && ({contact.jobTitle}
)}{[addr.street, [addr.postalCode, addr.city].filter(Boolean).join(" "), addr.region, addr.country] .filter(Boolean) .join(", ")}
{addr.label}
{formatBirthday(contact.birthday)}
)} {contact.notes && ({contact.notes}
)}{email.subject}
{email.preview}
{formatEmailDate(email.date)}