import { Mail, UserRound, X } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import AgentSpark from "./AgentSpark"; import { ALL_MAIL_LABEL, ALL_TYPES_ID, buildHandoffSummary, EMAIL_TYPE_OPTIONS, HANDOFF_LABELS, INSTRUCTION_EXAMPLES, } from "../utils/handoffUtils"; function ToggleSwitch({ checked, onChange, label }) { return ( ); } export default function HumanHandoffDrawer({ open, rule, saving, onClose, onSave, onTest, }) { const [ruleName, setRuleName] = useState(""); const [priority, setPriority] = useState(0); const [ownerEmail, setOwnerEmail] = useState(""); const [labels, setLabels] = useState([]); const [emailTypes, setEmailTypes] = useState([]); const [instructions, setInstructions] = useState(""); const [allowReplies, setAllowReplies] = useState(true); const [active, setActive] = useState(true); const [labelQuery, setLabelQuery] = useState(""); useEffect(() => { if (!open) return; setRuleName(rule?.name || ""); setPriority(rule?.priority ?? 0); setOwnerEmail(rule?.owner_email || ""); setLabels(rule?.labels || []); setEmailTypes(rule?.email_types || []); setInstructions(rule?.instructions || ""); setAllowReplies(rule?.allow_replies ?? true); setActive(rule?.active ?? true); setLabelQuery(""); }, [open, rule]); const summary = useMemo( () => buildHandoffSummary({ ownerEmail, labels, emailTypes, instructions, }), [ownerEmail, labels, emailTypes, instructions], ); const filteredLabels = HANDOFF_LABELS.filter((label) => label.toLowerCase().includes(labelQuery.trim().toLowerCase()), ); function toggleLabel(label) { if (label === ALL_MAIL_LABEL) { setLabels((current) => ( current.includes(ALL_MAIL_LABEL) ? [] : [ALL_MAIL_LABEL] )); return; } setLabels((current) => { const withoutAll = current.filter((item) => item !== ALL_MAIL_LABEL); return withoutAll.includes(label) ? withoutAll.filter((item) => item !== label) : [...withoutAll, label]; }); } function toggleEmailType(typeId) { if (typeId === ALL_TYPES_ID) { setEmailTypes((current) => ( current.includes(ALL_TYPES_ID) ? [] : [ALL_TYPES_ID] )); return; } setEmailTypes((current) => { const withoutAll = current.filter((item) => item !== ALL_TYPES_ID); return withoutAll.includes(typeId) ? withoutAll.filter((item) => item !== typeId) : [...withoutAll, typeId]; }); } function insertExample(example) { setInstructions((current) => { const trimmed = current.trim(); const addition = example.toLowerCase(); if (!trimmed) return `Hand off when there is a ${addition}.`; if (trimmed.toLowerCase().includes(addition)) return current; return `${trimmed.replace(/\.$/, "")}, or when there is a ${addition}.`; }); } if (!open) return null; return (