"use client";
import { useMemo } from "react";
import { useTranslations } from "next-intl";
import { BookUser, Users, Plus, UserPlus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { ContactCard } from "@/lib/jmap/types";
import { getContactDisplayName } from "@/stores/contact-store";
export type ContactCategory = "all" | { groupId: string };
interface ContactsSidebarProps {
groups: ContactCard[];
individuals: ContactCard[];
activeCategory: ContactCategory;
onSelectCategory: (category: ContactCategory) => void;
onCreateGroup: () => void;
onCreateContact: () => void;
className?: string;
}
export function ContactsSidebar({
groups,
individuals,
activeCategory,
onSelectCategory,
onCreateGroup,
onCreateContact,
className,
}: ContactsSidebarProps) {
const t = useTranslations("contacts");
const sortedGroups = useMemo(() => {
return [...groups].sort((a, b) =>
getContactDisplayName(a).localeCompare(getContactDisplayName(b))
);
}, [groups]);
const isAllActive = activeCategory === "all";
return (
{/* Header */}
{t("title")}
{/* Categories */}
{/* All contacts */}
{/* Groups section */}
{(sortedGroups.length > 0) && (
{sortedGroups.map((group) => {
const isActive = typeof activeCategory === "object" && activeCategory.groupId === group.id;
const memberCount = group.members
? Object.values(group.members).filter(Boolean).length
: 0;
return (
);
})}
)}
{sortedGroups.length === 0 && (
{t("tabs.groups")}
)}
);
}