"use client"; import { useState, type ReactNode } from "react"; import { Database } from "lucide-react"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { useI18n } from "@/i18n/i18n-context"; import type { KnowledgeBase } from "@/types/knowledge-base"; interface MountPickerProps { /** KBs available to mount — typically the global list minus already-mounted. */ kbs: KnowledgeBase[]; onPick: (kb: KnowledgeBase) => void; /** Render-prop trigger so the same picker can hang off either the empty- * state hero button or the compact "add more" affordance below the list. */ children: ReactNode; /** Where to anchor the popover relative to the trigger. */ align?: "start" | "center" | "end"; } /** * Searchable knowledge-base picker rendered inside a Popover. Picking commits * immediately and closes the popover — single-click feel matching the * "label / member picker" pattern used by Linear, GitHub and Vercel. * * The trigger is render-prop-driven so the surrounding UI can promote it into * a dominant primary button (when no KB is mounted yet) or demote it to a * compact dashed pill (once the user has at least one mount). */ export function MountPicker({ kbs, onPick, children, align = "start", }: MountPickerProps) { const { t } = useI18n(); const [open, setOpen] = useState(false); const handleSelect = (name: string) => { const kb = kbs.find((k) => k.knowledgeBaseName === name); if (!kb) return; onPick(kb); setOpen(false); }; return ( // `modal` is load-bearing: this picker opens from inside the chat config // Sheet, and a Radix Dialog's scroll lock cancels wheel events on portalled // content it doesn't own — without it the KB list simply refuses to scroll. // See components/ui/__tests__/popover-in-dialog.test.ts. {children} {t("chat.mount.noMatchingKb")} {kbs.length > 0 ? ( {kbs.map((kb) => ( {kb.knowledgeBaseName} ))} ) : null} ); }