"use client"; import { Button } from "@app/components/ui/button"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@app/components/ui/command"; import { Popover, PopoverContent, PopoverTrigger } from "@app/components/ui/popover"; import { cn } from "@app/lib/cn"; import { aiProviderTypeValues } from "@app/lib/aiProviderFormSchema"; import type { AiProviderType } from "@app/lib/aiProviderDefaults"; import { CheckIcon, ChevronsUpDown } from "lucide-react"; import { useTranslations } from "next-intl"; import { useMemo, useState } from "react"; export const aiProviderTypeLabelMap = { openai: "aiProviderTypeOpenai", anthropic: "aiProviderTypeAnthropic", googleGemini: "aiProviderTypeGoogleGemini", vertexAi: "aiProviderTypeVertexAi", bedrock: "aiProviderTypeBedrock", microsoftFoundry: "aiProviderTypeMicrosoftFoundry", openRouter: "aiProviderTypeOpenRouter", vercelAiGateway: "aiProviderTypeVercelAiGateway", custom: "aiProviderTypeCustom" } as const; const typeDescriptionMap = { openai: "aiProviderTypeOpenaiDescription", anthropic: "aiProviderTypeAnthropicDescription", googleGemini: "aiProviderTypeGoogleGeminiDescription", vertexAi: "aiProviderTypeVertexAiDescription", bedrock: "aiProviderTypeBedrockDescription", microsoftFoundry: "aiProviderTypeMicrosoftFoundryDescription", openRouter: "aiProviderTypeOpenRouterDescription", vercelAiGateway: "aiProviderTypeVercelAiGatewayDescription", custom: "aiProviderTypeCustomDescription" } as const; type AiProviderTypeSelectProps = { value: AiProviderType; onChange: (value: AiProviderType) => void; disabled?: boolean; className?: string; }; export function AiProviderTypeSelect({ value, onChange, disabled, className }: AiProviderTypeSelectProps) { const t = useTranslations(); const [open, setOpen] = useState(false); const options = useMemo( () => aiProviderTypeValues.map((type) => ({ type, title: t(aiProviderTypeLabelMap[type]), description: t(typeDescriptionMap[type]) })), [t] ); const selected = options.find((option) => option.type === value); return ( {t("aiProviderTypeNotFound")} {options.map((option) => ( { onChange(option.type); setOpen(false); }} >
{option.title} {option.description}
))}
); }