import React, { useState, useEffect } from 'react'; const STORAGE_KEY = 'gemini_api_key'; interface ApiKeySettingsProps { onKeyConfigured: (hasKey: boolean) => void; } export const ApiKeySettings: React.FC = ({ onKeyConfigured }) => { const [apiKey, setApiKey] = useState(''); const [showKey, setShowKey] = useState(false); const [hasStoredKey, setHasStoredKey] = useState(false); useEffect(() => { const storedKey = localStorage.getItem(STORAGE_KEY); if (storedKey) { setHasStoredKey(true); onKeyConfigured(true); } else { onKeyConfigured(false); } }, [onKeyConfigured]); const handleSaveKey = () => { if (apiKey.trim()) { localStorage.setItem(STORAGE_KEY, apiKey.trim()); setHasStoredKey(true); setApiKey(''); onKeyConfigured(true); } }; const handleClearKey = () => { localStorage.removeItem(STORAGE_KEY); setHasStoredKey(false); setApiKey(''); onKeyConfigured(false); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleSaveKey(); } }; if (hasStoredKey) { return (
API Key Configured
); } return (

Configure Gemini API Key

Enter your Gemini API key to use this app. Your key will be stored locally in your browser. Get your API key from{' '} Google AI Studio

setApiKey(e.target.value)} onKeyPress={handleKeyPress} placeholder="Enter your Gemini API key..." className="w-full px-4 py-2 bg-gray-800 border border-gray-600 rounded-lg text-white placeholder-gray-500 focus:outline-none focus:border-blue-500 pr-10" />
); }; export const getApiKey = (): string | null => { return localStorage.getItem(STORAGE_KEY); };