"use client"; import { useState, useEffect } from "react"; import { useAppStore } from "@/store/app-store"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Settings, Key, Eye, EyeOff, CheckCircle2, AlertCircle, Loader2, Zap, Sun, Moon, Palette } from "lucide-react"; export function SettingsView() { const { apiKeys, setApiKeys, setCurrentView, theme, setTheme } = useAppStore(); const [anthropicKey, setAnthropicKey] = useState(apiKeys.anthropic); const [googleKey, setGoogleKey] = useState(apiKeys.google); const [showAnthropicKey, setShowAnthropicKey] = useState(false); const [showGoogleKey, setShowGoogleKey] = useState(false); const [saved, setSaved] = useState(false); const [testingConnection, setTestingConnection] = useState(false); const [testResult, setTestResult] = useState<{ success: boolean; message: string } | null>(null); const [testingGeminiConnection, setTestingGeminiConnection] = useState(false); const [geminiTestResult, setGeminiTestResult] = useState<{ success: boolean; message: string } | null>(null); useEffect(() => { setAnthropicKey(apiKeys.anthropic); setGoogleKey(apiKeys.google); }, [apiKeys]); const handleTestConnection = async () => { setTestingConnection(true); setTestResult(null); try { const response = await fetch("/api/claude/test", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ apiKey: anthropicKey }), }); const data = await response.json(); if (response.ok && data.success) { setTestResult({ success: true, message: data.message || "Connection successful! Claude responded." }); } else { setTestResult({ success: false, message: data.error || "Failed to connect to Claude API." }); } } catch (error) { setTestResult({ success: false, message: "Network error. Please check your connection." }); } finally { setTestingConnection(false); } }; const handleTestGeminiConnection = async () => { setTestingGeminiConnection(true); setGeminiTestResult(null); try { const response = await fetch("/api/gemini/test", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ apiKey: googleKey }), }); const data = await response.json(); if (response.ok && data.success) { setGeminiTestResult({ success: true, message: data.message || "Connection successful! Gemini responded." }); } else { setGeminiTestResult({ success: false, message: data.error || "Failed to connect to Gemini API." }); } } catch (error) { setGeminiTestResult({ success: false, message: "Network error. Please check your connection." }); } finally { setTestingGeminiConnection(false); } }; const handleSave = () => { setApiKeys({ anthropic: anthropicKey, google: googleKey, }); setSaved(true); setTimeout(() => setSaved(false), 2000); }; return (
{/* Header Section */}

Settings

Configure your API keys and preferences

{/* Content Area */}
{/* API Keys Section */}

API Keys

Configure your AI provider API keys. Keys are stored locally in your browser.

{/* Claude/Anthropic API Key */}
{apiKeys.anthropic && ( )}
setAnthropicKey(e.target.value)} placeholder="sk-ant-..." className="pr-10 bg-zinc-950/50 border-white/10 text-white placeholder:text-zinc-500" data-testid="anthropic-api-key-input" />

Used for Claude AI features. Get your key at{" "} console.anthropic.com . Alternatively, the CLAUDE_CODE_OAUTH_TOKEN environment variable can be used.

{testResult && (
{testResult.success ? ( ) : ( )} {testResult.message}
)}
{/* Google API Key */}
{apiKeys.google && ( )}
setGoogleKey(e.target.value)} placeholder="AIza..." className="pr-10 bg-zinc-950/50 border-white/10 text-white placeholder:text-zinc-500" data-testid="google-api-key-input" />

Used for Gemini AI features (including image/design prompts). Get your key at{" "} makersuite.google.com

{geminiTestResult && (
{geminiTestResult.success ? ( ) : ( )} {geminiTestResult.message}
)}
{/* Security Notice */}

Security Notice

API keys are stored in your browser's local storage. Never share your API keys or commit them to version control.

{/* Appearance Section */}

Appearance

Customize the look and feel of your application.

{/* Save Button */}
); }