import { Input } from '@/components/ui/input' import { useLocalApiServer } from '@/hooks/useLocalApiServer' import { useState, useEffect } from 'react' import { Eye, EyeOff } from 'lucide-react' interface ApiKeyInputProps { showError?: boolean onValidationChange?: (isValid: boolean) => void } export function ApiKeyInput({ showError = false, onValidationChange, }: ApiKeyInputProps) { const { apiKey, setApiKey } = useLocalApiServer() const [inputValue, setInputValue] = useState(apiKey.toString()) const [showPassword, setShowPassword] = useState(false) const [error, setError] = useState('') const validateApiKey = (value: string) => { if (!value || value.trim().length === 0) { setError('API Key is required') onValidationChange?.(false) return false } setError('') onValidationChange?.(true) return true } useEffect(() => { if (showError) { validateApiKey(inputValue) } }, [showError, inputValue]) const handleChange = (e: React.ChangeEvent) => { const value = e.target.value setInputValue(value) // Clear error when user starts typing if (error && value.trim().length > 0) { setError('') onValidationChange?.(true) } } const handleBlur = () => { setApiKey(inputValue) // Validate on blur if showError is true if (showError) { validateApiKey(inputValue) } } const hasError = error && showError return (
{hasError && (

{error}

)}
) }