"use client"; import { useMemo } from "react"; import { useTranslations } from "next-intl"; import { Search, Plus, BookUser, Info } from "lucide-react"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { ContactListItem } from "./contact-list-item"; import { cn } from "@/lib/utils"; import type { ContactCard } from "@/lib/jmap/types"; import { getContactDisplayName } from "@/stores/contact-store"; interface ContactListProps { contacts: ContactCard[]; selectedContactId: string | null; searchQuery: string; onSearchChange: (query: string) => void; onSelectContact: (id: string) => void; onCreateNew: () => void; supportsSync: boolean; className?: string; } export function ContactList({ contacts, selectedContactId, searchQuery, onSearchChange, onSelectContact, onCreateNew, supportsSync, className, }: ContactListProps) { const t = useTranslations("contacts"); const filtered = useMemo(() => { if (!searchQuery) return contacts; const lower = searchQuery.toLowerCase(); return contacts.filter((c) => { const name = getContactDisplayName(c).toLowerCase(); const emails = c.emails ? Object.values(c.emails).map((e) => e.address.toLowerCase()) : []; return ( name.includes(lower) || emails.some((e) => e.includes(lower)) ); }); }, [contacts, searchQuery]); const sorted = useMemo(() => { return [...filtered].sort((a, b) => { const nameA = getContactDisplayName(a).toLowerCase(); const nameB = getContactDisplayName(b).toLowerCase(); return nameA.localeCompare(nameB); }); }, [filtered]); return (

{t("title")}

onSearchChange(e.target.value)} className="pl-9" />
{!supportsSync && (
{t("local_mode")}
)}
{sorted.length === 0 ? (

{searchQuery ? t("empty_search") : t("empty_state")}

) : (
{sorted.map((contact) => ( onSelectContact(contact.id)} /> ))}
)}
); }