"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" import { useApiKey } from "@/hooks/use-api-key" interface ApiKeyModalProps { isOpen: boolean onClose: () => void onSubmit: (key: string) => void } export function ApiKeyModal({ isOpen, onClose, onSubmit }: ApiKeyModalProps) { const [apiKeyInput, setApiKeyInput] = useState("") const [isLoading, setIsLoading] = useState(false) const [existingKey, setApiKey] = useApiKey() useEffect(() => { if (isOpen) { setApiKeyInput((current) => { if (existingKey && current === "") { return existingKey } return current }) } }, [isOpen, existingKey]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!apiKeyInput.trim()) return setIsLoading(true) await new Promise((resolve) => setTimeout(resolve, 500)) setIsLoading(false) onSubmit(apiKeyInput.trim()) setApiKeyInput("") } const handleDelete = () => { setApiKey(null) setApiKeyInput("") 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." : "You've used all your weekly credits! Add your Together API key for unlimited generation."}
setApiKeyInput(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" /> {apiKeyInput && ( )}
Get your Together API key

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

) }