import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card } from '@/components/ui/card'; import { Loader2, Play, Copy, Check } from 'lucide-react'; import { toast } from 'sonner'; export const APIPlayground = () => { const [testUrl, setTestUrl] = useState('https://example.com'); const [loading, setLoading] = useState(false); const [response, setResponse] = useState(null); const [copied, setCopied] = useState(false); const handleTest = async () => { setLoading(true); try { const res = await fetch(`${import.meta.env.VITE_SUPABASE_URL}/functions/v1/analyze-seo`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${import.meta.env.VITE_SUPABASE_ANON_KEY}` }, body: JSON.stringify({ url: testUrl }) }); const data = await res.json(); setResponse(data); if (data.success) { toast.success('Analysis completed!'); } else { toast.error(data.error || 'Analysis failed'); } } catch (error) { toast.error('Failed to call API'); setResponse({ error: 'Network error' }); } finally { setLoading(false); } }; const copyResponse = () => { navigator.clipboard.writeText(JSON.stringify(response, null, 2)); setCopied(true); toast.success('Copied to clipboard!'); setTimeout(() => setCopied(false), 2000); }; return (

Try it out

setTestUrl(e.target.value)} placeholder="Enter URL to analyze" className="flex-1" />
{response && (

Response

            {JSON.stringify(response, null, 2)}
          
)}
); };