import { Trans, useLingui } from "@lingui/react/macro"; import type { Bot } from "@rakazo/contracts"; import { BotAvatar, Command, CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator, } from "@rakazo/ui-web"; import { Info, Lock, Plus, Users } from "lucide-react"; import { useMemo, useState } from "react"; /** 1:1 conversation: open an existing bot or create a new one. */ export function ConversationBotPicker({ bots, onCreateBot, onOpenBot, }: { bots: Bot[]; onCreateBot: () => void; onOpenBot: (botId: string) => void; }) { const { t } = useLingui(); const [query, setQuery] = useState(""); const needle = query.trim().toLowerCase(); const matched = useMemo(() => { if (!needle) return bots; return bots.filter( (bot) => bot.name.toLowerCase().includes(needle) || bot.title.toLowerCase().includes(needle), ); }, [bots, needle]); const createLabel = t`Create new Bot`; const createText = createLabel.toLowerCase(); const showCreate = !needle || createText.includes(needle) || needle.split(/\s+/).every((part) => createText.includes(part)); return (
No bots match {showCreate ? ( onCreateBot()} className="gap-2" > ) : null} {matched.map((bot) => ( onOpenBot(bot.id)} className="gap-2" > {bot.name} ))}
); } export function BotCreatePicker({ bots, onCreateBot, onOpenBot, onCreateGroup, onCreateSpace, onShowGroupInfo, onShowSpaceInfo, }: { bots: Bot[]; onCreateBot: () => void; onOpenBot: (botId: string) => void; onCreateGroup: () => void; onCreateSpace: () => void; onShowGroupInfo: () => void; onShowSpaceInfo: () => void; }) { const { t } = useLingui(); const [query, setQuery] = useState(""); const needle = query.trim().toLowerCase(); const matched = useMemo(() => { if (!needle) return bots; return bots.filter( (bot) => bot.name.toLowerCase().includes(needle) || bot.title.toLowerCase().includes(needle), ); }, [bots, needle]); const showCreate = !needle || "create new bot".includes(needle) || needle.split(/\s+/).every((part) => "create new bot".includes(part)); return (
No bots match {showCreate ? ( onCreateBot()} className="gap-2" > ) : null} {matched.map((bot) => ( onOpenBot(bot.id)} className="gap-2" > {bot.name} ))} onCreateGroup()} className="gap-2" > onCreateSpace()} className="gap-2" >
); }