"use client"; import { useState } from "react"; const CUSTOM_VALUE = "__custom__"; export default function ApiKeySelect({ value, onChange, apiKeys = [], cloudEnabled = false, className = "" }) { const isCustom = !apiKeys.some((k) => k.key === value) && value !== ""; const [mode, setMode] = useState(() => { if (!value) return apiKeys.length > 0 ? apiKeys[0].key : CUSTOM_VALUE; if (apiKeys.some((k) => k.key === value)) return value; return CUSTOM_VALUE; }); const [customInput, setCustomInput] = useState(isCustom ? value : ""); const handleSelect = (e) => { const next = e.target.value; setMode(next); if (next === CUSTOM_VALUE) { setCustomInput(""); onChange(""); } else { onChange(next); } }; const handleCustomInput = (e) => { const v = e.target.value; setCustomInput(v); onChange(v); }; const noKeys = apiKeys.length === 0 && mode !== CUSTOM_VALUE; if (noKeys && mode !== CUSTOM_VALUE) { return ( {cloudEnabled ? "No API keys - Create one in Keys page" : "sk_9router (default)"} ); } return (
{mode === CUSTOM_VALUE && ( )}
); }