'use client'; import * as React from 'react'; import { Settings, Eye, EyeOff, Check, Trash2, Key } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from '@/components/ui/sheet'; import { useApiKeys } from '@/contexts/api-keys-context'; import { PROVIDER_CONFIGS, type ImageProvider } from '@/lib/api-config'; import { Icons } from './icons'; import { cn } from '@/lib/utils'; interface ApiKeyInputProps { provider: ImageProvider; label: string; placeholder: string; icon: React.ComponentType<{ className?: string }>; } function ApiKeyInput({ provider, label, placeholder, icon: Icon }: ApiKeyInputProps) { const { getApiKey, setApiKey, clearApiKey, hasKey } = useApiKeys(); const [showKey, setShowKey] = React.useState(false); const [localValue, setLocalValue] = React.useState(''); const [isSaved, setIsSaved] = React.useState(false); // Sync local value with context on mount and when context changes React.useEffect(() => { const contextValue = getApiKey(provider); setLocalValue(contextValue); setIsSaved(contextValue.length > 0); }, [getApiKey, provider]); const handleSave = () => { setApiKey(provider, localValue); setIsSaved(true); setTimeout(() => setIsSaved(false), 2000); }; const handleClear = () => { setLocalValue(''); clearApiKey(provider); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleSave(); } }; const isConfigured = hasKey(provider); return (