import { useState } from "react"; import { Check, ChevronsUpDown, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; interface Model { id: string; name: string; pricing?: { prompt: string; completion: string; }; } interface ModelComboboxProps { models: Model[]; value: string; onValueChange: (value: string) => void; placeholder?: string; isLoading?: boolean; disabled?: boolean; className?: string; testId?: string; } export function ModelCombobox({ models, value, onValueChange, placeholder = "Sélectionner un modèle", isLoading = false, disabled = false, className, testId, }: ModelComboboxProps) { const [open, setOpen] = useState(false); const [searchQuery, setSearchQuery] = useState(""); const selectedModel = models.find((model) => model.id === value); const filteredModels = models.filter((model) => model.name.toLowerCase().includes(searchQuery.toLowerCase()) || model.id.toLowerCase().includes(searchQuery.toLowerCase()) ); return ( Aucun modèle trouvé. {filteredModels.map((model) => ( { onValueChange(currentValue); setOpen(false); setSearchQuery(""); }} data-testid={`${testId}-option-${model.id}`} >
{model.name} {model.pricing && ( Prompt: ${model.pricing.prompt} | Completion: ${model.pricing.completion} )}
))}
); }