import { useState } from "react"; import { Plus, Trash2 } from "lucide-react"; import { useSettings, type LabelVisibility } from "@/store/settings"; import { labelTree, descendantKeywords } from "@/lib/labelTree"; import { useMemo } from "react"; import { CALENDAR_COLORS, ColorSwatches } from "@/ui/misc"; import { promptDialog } from "@/ui/dialog"; import { t, tNode } from "@/lib/i18n"; export function LabelsSettings() { const labels = useSettings((s) => s.settings.labels); const update = useSettings((s) => s.update); const [editing, setEditing] = useState(null); const roots = useMemo(() => labelTree(labels), [labels]); const descendantsOf = (keyword: string) => descendantKeywords(roots, keyword); const add = async () => { const name = await promptDialog({ title: t("New label"), placeholder: t("Label name") }); if (!name?.trim()) return; const keyword = name.trim().toLowerCase().replace(/[^a-z0-9_.-]+/g, "_").replace(/^_+|_+$/g, "") || `label${Date.now()}`; if (labels.some((l) => l.keyword === keyword)) return; update({ labels: [...labels, { keyword, name: name.trim(), color: CALENDAR_COLORS[labels.length % CALENDAR_COLORS.length]! }] }); }; return (

{t("Labels")}

{t("Labels are IMAP keywords stored on your messages, so every other client sees them. Names, colours and nesting are ihasmail\u2019s own and follow your account. Nesting is display only \u2014 it rewrites nothing in the mailbox.")}

{labels.map((l) => (
{editing === l.keyword ? ( { update({ labels: labels.map((x) => (x.keyword === l.keyword ? { ...x, name: e.target.value || x.name } : x)) }); setEditing(null); }} onKeyDown={(e) => { if (e.key === "Enter") (e.target as HTMLInputElement).blur(); }} style={{ width: 240 }} /> ) : (

setEditing(l.keyword)}>{l.name} ({l.keyword})

)}
update({ labels: labels.map((x) => (x.keyword === l.keyword ? { ...x, color: c } : x)) })} />
))}

{tNode("Tip: press {key} on a conversation to apply labels. Search with {operator}.", { key: l, operator: label:name })}

); }