"use client";
import { useTranslations } from "next-intl";
import { Mail, Phone, Building, MapPin, StickyNote, Pencil, Trash2, BookUser, Copy, Send } from "lucide-react";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { ContactCard } from "@/lib/jmap/types";
import { getContactDisplayName, getContactPrimaryEmail } from "@/stores/contact-store";
import { toast } from "@/stores/toast-store";
interface ContactDetailProps {
contact: ContactCard | null;
onEdit: () => void;
onDelete: () => void;
className?: string;
}
export function ContactDetail({ contact, onEdit, onDelete, className }: ContactDetailProps) {
const t = useTranslations("contacts");
if (!contact) {
return (
{t("detail.no_contact_selected")}
);
}
const name = getContactDisplayName(contact);
const email = getContactPrimaryEmail(contact);
const emails = contact.emails ? Object.values(contact.emails) : [];
const phones = contact.phones ? Object.values(contact.phones) : [];
const orgs = contact.organizations ? Object.values(contact.organizations) : [];
const addresses = contact.addresses ? Object.values(contact.addresses) : [];
const notes = contact.notes ? Object.values(contact.notes) : [];
return (
{name || "—"}
{orgs.length > 0 && orgs[0].name && (
{orgs[0].name}
)}
{emails.length > 0 && (
{emails.map((e, i) => (
{e.address}
{e.contexts && (
)}
))}
)}
{phones.length > 0 && (
{phones.map((p, i) => (
{p.number}
{p.contexts && (
)}
))}
)}
{orgs.length > 0 && (
{orgs.map((o, i) => (
{o.name}
{o.units && o.units.length > 0 && (
— {o.units.map(u => u.name).join(", ")}
)}
))}
)}
{addresses.length > 0 && (
{addresses.map((a, i) => (
{[a.street, a.locality, a.region, a.postcode, a.country].filter(Boolean).join(", ")}
{a.contexts && (
)}
))}
)}
{notes.length > 0 && (
{notes.map((n, i) => (
{n.note}
))}
)}
);
}
function Section({ icon: Icon, title, children }: { icon: React.ComponentType<{ className?: string }>; title: string; children: React.ReactNode }) {
return (
);
}
function ContextBadge({ contexts }: { contexts: Record }) {
const labels = Object.keys(contexts).filter(k => contexts[k]);
if (labels.length === 0) return null;
return (
{labels.join(", ")}
);
}