import { ExternalLink, Eye, EyeOff, Loader2, X } from "lucide-react" import { useState } from "react" import { useTranslation } from "react-i18next" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { useApiKeys } from "../../hooks/use-api-keys" import { KeyStatusIndicator } from "./key-status-indicator" interface ApiKeyInputProps { value: string onChange: (value: string) => void placeholder?: string service: string label?: string testable?: boolean links?: Array<{ text: string url: string }> } /** * Переиспользуемый компонент для ввода API ключей * Поддерживает скрытие/показ, валидацию и тестирование */ export function ApiKeyInput({ value, onChange, placeholder, service, label, testable = false, links = [], }: ApiKeyInputProps) { const { t } = useTranslation() const { getApiKeyStatus, testApiKey } = useApiKeys() const [showKey, setShowKey] = useState(false) const [isTesting, setIsTesting] = useState(false) const status = getApiKeyStatus(service) const handleTest = async () => { if (!value || isTesting) return setIsTesting(true) try { await testApiKey(service) } finally { setIsTesting(false) } } const handleClear = () => { onChange("") setShowKey(false) } return (
{/* Label и статус */} {label && (
)} {/* Поле ввода */}
onChange(e.target.value)} placeholder={placeholder} className="h-9 pr-16 font-mono text-sm" /> {/* Кнопки в поле ввода */}
{/* Показать/скрыть ключ */} {value && ( )} {/* Очистить ключ */} {value && ( )}
{/* Кнопка тестирования */} {testable && ( )}
{/* Ссылки */} {links.length > 0 && (
{links.map((link, index) => ( ))}
)} {/* Статусное сообщение */} {status === "invalid" && (

{t("dialogs.userSettings.invalidKey", "Неверный API ключ или проблемы с подключением")}

)} {status === "valid" && (

{t("dialogs.userSettings.validKey", "API ключ работает корректно")}

)}
) }