import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { Badge } from "@/components/ui/badge"; 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"; import { cn } from "@/lib/utils"; export function ModelSelector({ options, value, onValueChange, icon, placeholder = "Select model...", searchPlaceholder = "Search model...", noOptionsPlaceholder = "No models available", custom = false, }: { options: { value: string; label: string; default?: boolean; }[]; value: string; icon?: React.ReactNode; placeholder?: string; searchPlaceholder?: string; noOptionsPlaceholder?: string; custom?: boolean; onValueChange: (value: string) => void; }) { const [open, setOpen] = useState(false); const [searchValue, setSearchValue] = useState(""); useEffect(() => { if (value && (!options.find((option) => option.value === value) && !custom)) { onValueChange(""); } }, [options, value, custom, onValueChange]); return ( {/** biome-ignore lint/a11y/useSemanticElements: has to be a Button */} {noOptionsPlaceholder} {options.map((option) => ( { if (currentValue !== value) { onValueChange(currentValue); } setOpen(false); }} >
{option.label} {/* {option.default && ( // DISABLING DEFAULT TAG FOR NOW Default )} */}
))} {custom && searchValue && !options.find((option) => option.value === searchValue) && ( { if (currentValue !== value) { onValueChange(currentValue); } setOpen(false); }} >
{searchValue} Custom
)}
); }