"use client" import { useMemo, useState } from "react" import { Button } from "@/components/ui/button" import { useContactsStore } from "@/lib/contacts/contacts-store" import { fullContactDisplayName } from "@/lib/contacts/types" import { avatarColor, senderInitial } from "@/lib/sender-display" export function AddCoordinatesView() { const { getCoordinateSuggestions, updateContact } = useContactsStore() const suggestions = useMemo(() => getCoordinateSuggestions(), [getCoordinateSuggestions]) const [dismissed, setDismissed] = useState>(new Set()) const visible = suggestions.filter((s) => !dismissed.has(s.contact.id)) function handleAdd(contactId: string, field: string, value: string) { updateContact(contactId, { [field]: value }) setDismissed((s) => new Set(s).add(contactId)) } function handleIgnore(contactId: string) { setDismissed((s) => new Set(s).add(contactId)) } function handleAddAll() { for (const s of visible) { updateContact(s.contact.id, { [s.suggestedField]: s.suggestedValue }) } setDismissed(new Set(suggestions.map((s) => s.contact.id))) } return (

Ajouter des coordonnées ({visible.length})

{visible.length > 0 && ( )}
{visible.length === 0 && (

Aucune suggestion disponible

)}
{visible.map((suggestion) => { const { contact, suggestedField, suggestedValue } = suggestion const displayName = fullContactDisplayName(contact) const name = displayName || contact.emails[0]?.value || "?" const color = avatarColor(name) const initial = senderInitial(name) return (

Contact à modifier

{contact.avatarUrl ? ( {name} ) : (
{initial}
)}

{name}

{contact.emails[0] && (

{contact.emails[0].value}

)} {contact.phones[0] && (

{contact.phones[0].value} ({contact.phones[0].label})

)}

Détails à ajouter

{suggestedValue}

) })}
) }