import { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { LucideIcon } from "../lib/iconData"; const STATUS_ICONS = { researching: "search", ordered: "truck", arrived: "check", } as const; type CandidateStatus = keyof typeof STATUS_ICONS; interface StatusBadgeProps { status: CandidateStatus; onStatusChange: (status: CandidateStatus) => void; } export function StatusBadge({ status, onStatusChange }: StatusBadgeProps) { const { t } = useTranslation("threads"); const [isOpen, setIsOpen] = useState(false); const containerRef = useRef(null); const STATUS_LABELS: Record = { researching: t("statusBadge.researching"), ordered: t("statusBadge.ordered"), arrived: t("statusBadge.arrived"), }; useEffect(() => { if (!isOpen) return; function handleClickOutside(e: MouseEvent) { if ( containerRef.current && !containerRef.current.contains(e.target as Node) ) { setIsOpen(false); } } function handleEscape(e: KeyboardEvent) { if (e.key === "Escape") { setIsOpen(false); } } document.addEventListener("mousedown", handleClickOutside); document.addEventListener("keydown", handleEscape); return () => { document.removeEventListener("mousedown", handleClickOutside); document.removeEventListener("keydown", handleEscape); }; }, [isOpen]); return (
{isOpen && (
{(Object.keys(STATUS_ICONS) as CandidateStatus[]).map((key) => { const isActive = key === status; return ( ); })}
)}
); }