"use client"; import { useTranslations } from "next-intl"; import { X } from "lucide-react"; import { cn } from "@/lib/utils"; import { SearchFilters } from "@/lib/jmap/search-utils"; interface SearchChipsProps { filters: SearchFilters; onRemoveFilter: (key: keyof SearchFilters) => void; onClearAll: () => void; className?: string; } export function SearchChips({ filters, onRemoveFilter, onClearAll, className, }: SearchChipsProps) { const t = useTranslations("advanced_search"); const chips: { key: keyof SearchFilters; label: string; value: string }[] = []; if (filters.from) { chips.push({ key: "from", label: t("from"), value: filters.from }); } if (filters.to) { chips.push({ key: "to", label: t("to"), value: filters.to }); } if (filters.subject) { chips.push({ key: "subject", label: t("subject"), value: filters.subject }); } if (filters.body) { chips.push({ key: "body", label: t("body"), value: filters.body }); } if (filters.hasAttachment !== null) { chips.push({ key: "hasAttachment", label: t("has_attachment"), value: filters.hasAttachment ? t("yes") : t("no"), }); } if (filters.dateAfter) { chips.push({ key: "dateAfter", label: t("date_after"), value: filters.dateAfter }); } if (filters.dateBefore) { chips.push({ key: "dateBefore", label: t("date_before"), value: filters.dateBefore }); } if (filters.isUnread !== null) { chips.push({ key: "isUnread", label: filters.isUnread ? t("unread") : t("read"), value: "", }); } if (filters.isStarred !== null) { chips.push({ key: "isStarred", label: t("starred"), value: filters.isStarred ? t("yes") : t("no"), }); } if (chips.length === 0) return null; return (
{chips.map((chip) => ( {chip.label} {chip.value && ( <> : {chip.value} )} ))} {chips.length > 1 && ( )}
); }