"use client"; import React, { useState } from 'react'; import { User, Mail, Phone, Building, MapPin, Edit2, Save, X } from 'lucide-react'; interface Contact { id: string; fullName?: string; email?: string; phone?: string; organization?: string; address?: string; notes?: string; group?: string; } interface ContactDetailsProps { contact: Contact | null; onSave?: (contact: Contact) => void; onDelete?: (contact: Contact) => void; } export const ContactDetails: React.FC = ({ contact, onSave, onDelete }) => { const [isEditing, setIsEditing] = useState(false); const [editedContact, setEditedContact] = useState(null); // Initialize edited contact when a contact is selected React.useEffect(() => { setEditedContact(contact); setIsEditing(false); }, [contact]); if (!contact) { return (

Sélectionnez un contact pour voir les détails

); } const handleSave = () => { if (editedContact && onSave) { onSave(editedContact); setIsEditing(false); } }; const handleCancel = () => { setEditedContact(contact); setIsEditing(false); }; const renderField = (label: string, value: string | undefined, field: keyof Contact, icon: React.ReactNode) => { const bgColor = { email: 'bg-blue-50', phone: 'bg-green-50', organization: 'bg-purple-50', address: 'bg-orange-50' }[field] || 'bg-gray-50'; const textColor = { email: 'text-blue-500', phone: 'text-green-500', organization: 'text-purple-500', address: 'text-orange-500' }[field] || 'text-gray-500'; return (
{icon}

{label}

{isEditing ? ( setEditedContact(prev => prev ? {...prev, [field]: e.target.value} : null)} className="w-full text-sm text-carnet-text-primary bg-transparent border-b border-primary focus:outline-none" /> ) : (

{value}

)}
); }; return (
{isEditing ? ( setEditedContact(prev => prev ? {...prev, fullName: e.target.value} : null)} className="text-xl font-semibold text-carnet-text-primary bg-transparent border-b border-primary focus:outline-none" placeholder="Nom complet" /> ) : (

{contact.fullName || contact.email || 'Sans nom'}

)}
{isEditing ? ( <> ) : ( <> {onDelete && ( )} )}
{renderField('Email', contact.email, 'email', )} {renderField('Téléphone', contact.phone, 'phone', )} {renderField('Organisation', contact.organization, 'organization', )} {renderField('Adresse', contact.address, 'address', )}

Notes

{isEditing ? (