'use client' import { Check, Copy } from 'lucide-react' import { useEffect, useState } from 'react' import { Button } from 'ui' interface CopyDocPromptProps { title: string markdownPath: string intent: 'create-app' | 'add-to-project' } export function CopyDocPrompt({ title, markdownPath, intent }: CopyDocPromptProps) { const [status, setStatus] = useState<'idle' | 'copied' | 'error'>('idle') useEffect(() => { if (status !== 'copied') return const timeout = window.setTimeout(() => setStatus('idle'), 2500) return () => window.clearTimeout(timeout) }, [status]) async function copyPrompt() { const url = new URL(markdownPath, window.location.origin).href const task = intent === 'create-app' ? `Help me create a new application using ${title} from Supabase Library. Inspect my workspace and create the app in a suitable directory.` : `Help me add ${title} from Supabase Library to my existing project. Inspect my project structure and reuse any Supabase client setup that is already in place.` const prompt = [ task, `Read ${url} for the complete guide before making changes.`, "To add the block's files, prefer the guide's shadcn install command over copying them from the registry JSON; the CLI also installs npm dependencies and related blocks.", 'Follow the rest of the guide, adapting it to my project, and verify that the setup works.', ].join(' ') try { await navigator.clipboard.writeText(prompt) setStatus('copied') } catch { setStatus('error') } } return (
{status === 'error' ? 'Unable to copy the prompt. Try again.' : status === 'copied' ? 'Prompt copied to clipboard' : ''}
) }