"use client"; import type React from "react"; import { useState, useEffect } from "react"; import { Key, ExternalLink, ArrowRight, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from "@/components/ui/dialog"; import { TOGETHER_LINK } from "@/lib/utils"; interface ApiKeyModalProps { isOpen: boolean; onClose: () => void; onSubmit: (key: string) => void; } export function ApiKeyModal({ isOpen, onClose, onSubmit }: ApiKeyModalProps) { const [apiKey, setApiKey] = useState(""); const [isLoading, setIsLoading] = useState(false); const [existingKey, setExistingKey] = useState(null); useEffect(() => { if (typeof window !== "undefined" && isOpen) { const storedKey = localStorage.getItem("together_api_key"); setExistingKey(storedKey); setApiKey((current) => { if (storedKey && current === "") { return storedKey; } return current; }); } }, [isOpen]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!apiKey.trim()) return; setIsLoading(true); await new Promise((resolve) => setTimeout(resolve, 500)); setIsLoading(false); onSubmit(apiKey.trim()); setApiKey(""); }; const handleDelete = () => { localStorage.removeItem("together_api_key"); setExistingKey(null); setApiKey(""); onClose(); }; return (
{existingKey ? "Update your API key" : "Add your API key to continue"} {existingKey ? "Update your Together API key or add a new one. You can also delete your existing key." : "Your first page was free! Add your Together API key to generate more pages."}
setApiKey(e.target.value)} placeholder={existingKey ? "Your current API key" : "Enter your API key..."} className="bg-secondary border-border/50 text-white placeholder-muted-foreground py-5 pr-10" /> {apiKey && ( )}
Get your free API key

Your API key is stored locally and never stored on our servers.

); }