import { useState, useRef, useEffect } from "preact/hooks"; const STATUS_OPTIONS = [ { value: "replied", label: "Junwon to reply" }, { value: "processing", label: "Ace is working" }, { value: "skipped", label: "Waiting" }, { value: "no_reply", label: "Chose no reply" }, { value: "failed", label: "Failed" }, { value: "archived", label: "Archived" }, ]; function statusLabel(status: string): string { const opt = STATUS_OPTIONS.find((o) => o.value === status); if (opt) return opt.label; if (status === "processing") return "Ace is working"; if (status === "queued") return "In queue"; if (status === "stalled") return "Stalled"; if (status === "skipped") return "Waiting"; return status; } interface Props { status: string; onChangeStatus?: (newStatus: string) => void; onDelete?: () => void; hasLinear?: boolean; } export default function StatusBadge({ status, onChangeStatus, onDelete, hasLinear }: Props) { const [open, setOpen] = useState(false); const ref = useRef(null); useEffect(() => { if (!open) return; const handler = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; document.addEventListener("click", handler, true); return () => document.removeEventListener("click", handler, true); }, [open]); return (
{ e.stopPropagation(); if (onChangeStatus) setOpen(!open); }} > {statusLabel(status)} {open && (
{STATUS_OPTIONS.map((opt) => (
{ e.stopPropagation(); if (opt.value !== status && onChangeStatus) onChangeStatus(opt.value); setOpen(false); }} > {opt.label}
))} {onDelete && ( <>
{ e.stopPropagation(); onDelete(); setOpen(false); }} > Delete
)}
)}
); }