"use client"; import { useState, useEffect } from "react"; import { Key } from "lucide-react"; interface APIKeyInputProps { onKeySubmit: (key: string) => void; } export function APIKeyInput({ onKeySubmit }: APIKeyInputProps) { const [key, setKey] = useState(""); const [isOpen, setIsOpen] = useState(false); useEffect(() => { const envKey = process.env.NEXT_PUBLIC_GEMINI_API_KEY; const storedKey = localStorage.getItem("gemini_api_key"); if (envKey) { onKeySubmit(envKey); } else if (storedKey) { onKeySubmit(storedKey); } else { setIsOpen(true); } }, [onKeySubmit]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (key.trim()) { localStorage.setItem("gemini_api_key", key.trim()); onKeySubmit(key.trim()); setIsOpen(false); } }; if (!isOpen) { return ( ); } return (
To receive AI feedback, please enter your Google Gemini API key. It will be stored locally in your browser.