import { ChevronRight, Search } from "lucide-react" import { useState } from "react" import { ProviderLogo } from "@/components/provider-logo" import { SettingsHeader } from "@/components/settings/settings-header" import { ScrollArea } from "@/components/ui/scroll-area" import { useDictionary } from "@/hooks/use-dictionary" import { filterProviderGroups, PROVIDER_NOTE_KEYS } from "@/lib/provider-setup" import { PROVIDER_INFO, type ProviderName } from "@/lib/types/model-config" /** Every provider in groups, with a search; picking one adds it */ export function ProviderPicker({ added, onPick, onBack, }: { /** Provider types the user has already added */ added: ProviderName[] onPick: (provider: ProviderName) => void onBack: () => void }) { const dict = useDictionary() const t = dict.modelConfig const [query, setQuery] = useState("") const groups = filterProviderGroups(query) const groupLabels: Record = { vendors: t.groupVendors, aggregators: t.groupAggregators, cloud: t.groupCloud, selfHosted: t.groupSelfHosted, } const notes = t as Record return (

{t.addProvider}

setQuery(e.target.value)} onKeyDown={(e) => { // Enter that confirms an IME candidate picks nothing if ( e.nativeEvent.isComposing || e.keyCode === 229 ) { return } // Enter picks the first match const first = groups[0]?.providers[0] if (e.key === "Enter" && query.trim() && first) { e.preventDefault() onPick(first) } }} placeholder={t.searchProviders} aria-label={t.searchProviders} className="h-10 w-full rounded-xl border border-border bg-background pr-3 pl-9 text-[13px] outline-none placeholder:text-muted-foreground focus-visible:border-foreground/40 focus-visible:ring-2 focus-visible:ring-ring/20" />
{groups.length === 0 && (

{t.noProvidersFound}

)} {groups.map((group) => (

{groupLabels[group.id]}

{group.providers.map((provider) => { const noteKey = PROVIDER_NOTE_KEYS[provider] const note = [ noteKey && notes[noteKey], added.includes(provider) && t.added, ] .filter(Boolean) .join(" ยท ") return ( ) })}
))}
) }