"use client"; import { useState, useRef, useEffect } from "react"; import { ChevronDown } from "lucide-react"; import { useI18n } from "@/lib/i18n/provider"; export type ConversationFilter = "all" | "mine" | "others"; export type ConversationListStatus = "open" | "closed"; interface ConversationHeaderProps { filter: ConversationFilter; onFilterChange: (filter: ConversationFilter) => void; /** 与「全部对话」同一行右侧:进行中 / 历史 */ listStatus?: ConversationListStatus; onListStatusChange?: (status: ConversationListStatus) => void; } const FILTER_OPTIONS: { value: ConversationFilter; label: string }[] = [ { value: "all", label: "全部对话" }, { value: "mine", label: "我的对话" }, { value: "others", label: "他人对话" }, ]; export function ConversationHeader({ filter, onFilterChange, listStatus, onListStatusChange, }: ConversationHeaderProps) { const { t } = useI18n(); const [open, setOpen] = useState(false); const ref = useRef(null); const options = [ { value: "all" as const, label: t("agent.conversations.filter.all") }, { value: "mine" as const, label: t("agent.conversations.filter.mine") }, { value: "others" as const, label: t("agent.conversations.filter.others") }, ]; const currentLabel = options.find((o) => o.value === filter)?.label ?? t("agent.conversations.filter.all"); useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false); }; if (open) document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, [open]); const showListStatus = listStatus !== undefined && typeof onListStatusChange === "function"; return (
{open && (
{options.map((opt) => ( ))}
)}
{showListStatus && (
)}
); }