'use client' import { useState, useCallback } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { Globe, Loader2, AlertCircle, CheckCircle2, Code, FileText, Link2, ExternalLink } from 'lucide-react' interface DocsAnalysis { title: string description: string platform: string | null installCommands: Array<{ command: string packageManager?: string label?: string }> prerequisites: string[] codeBlockCount: number sectionCount: number relatedUrls: Array<{ url: string text: string type: string }> } interface UrlTabProps { onGenerated: (content: string) => void } export default function UrlTab({ onGenerated }: UrlTabProps) { const [url, setUrl] = useState('') const [isAnalyzing, setIsAnalyzing] = useState(false) const [isGenerating, setIsGenerating] = useState(false) const [analysis, setAnalysis] = useState(null) const [error, setError] = useState(null) const handleAnalyze = useCallback(async () => { if (!url.trim()) { setError('Please enter a documentation URL') return } // Basic URL validation let normalizedUrl = url.trim() if (!normalizedUrl.startsWith('http://') && !normalizedUrl.startsWith('https://')) { normalizedUrl = `https://${normalizedUrl}` } try { new URL(normalizedUrl) } catch { setError('Please enter a valid URL') return } setIsAnalyzing(true) setError(null) setAnalysis(null) try { const params = new URLSearchParams({ url: normalizedUrl, type: 'docs' }) const response = await fetch(`/api/generate-install?${params}`) const data = await response.json() if (!response.ok) { throw new Error(data.error || 'Analysis failed') } setAnalysis(data.analysis) } catch (err) { setError(err instanceof Error ? err.message : 'Analysis failed') } finally { setIsAnalyzing(false) } }, [url]) const handleGenerate = useCallback(async () => { if (!url.trim()) { setError('Please enter a documentation URL') return } let normalizedUrl = url.trim() if (!normalizedUrl.startsWith('http://') && !normalizedUrl.startsWith('https://')) { normalizedUrl = `https://${normalizedUrl}` } setIsGenerating(true) setError(null) try { const response = await fetch('/api/generate-install', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: normalizedUrl, type: 'docs', }), }) const data = await response.json() if (!response.ok) { throw new Error(data.error || 'Generation failed') } if (data.installMd) { onGenerated(data.installMd) } else { throw new Error('No install.md content returned') } } catch (err) { setError(err instanceof Error ? err.message : 'Generation failed') } finally { setIsGenerating(false) } }, [url, onGenerated]) const handleKeyDown = useCallback((e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() if (analysis) { handleGenerate() } else { handleAnalyze() } } }, [analysis, handleAnalyze, handleGenerate]) const platformColors: Record = { mintlify: 'bg-green-500/20 text-green-300', docusaurus: 'bg-green-500/20 text-green-300', gitbook: 'bg-blue-500/20 text-blue-300', readme: 'bg-purple-500/20 text-purple-300', vitepress: 'bg-emerald-500/20 text-emerald-300', mkdocs: 'bg-cyan-500/20 text-cyan-300', sphinx: 'bg-orange-500/20 text-orange-300', nextra: 'bg-indigo-500/20 text-indigo-300', } return (
{/* URL Input */}
{ setUrl(e.target.value) setAnalysis(null) setError(null) }} onKeyDown={handleKeyDown} placeholder="docs.example.com/getting-started" className="w-full pl-10 pr-4 py-3 bg-black border border-neutral-700 rounded-lg text-white placeholder-neutral-500 focus:outline-none focus:border-white transition-colors" />

Enter any documentation page URL - we'll extract installation instructions

{/* Error */} {error && (

{error}

)}
{/* Analysis Results */} {analysis && (

{analysis.title}

{analysis.description && (

{analysis.description}

)}
{/* Stats Row */}
{analysis.platform && ( {analysis.platform} )}
{analysis.codeBlockCount} code blocks
{analysis.sectionCount} sections
{/* Prerequisites */} {analysis.prerequisites.length > 0 && (

Prerequisites Detected

{analysis.prerequisites.map((prereq, index) => ( {prereq} ))}
)} {/* Install Commands */} {analysis.installCommands.length > 0 && (

Install Commands Found

{analysis.installCommands.slice(0, 5).map((cmd, index) => (
{cmd.packageManager && ( {cmd.packageManager} )} {cmd.command}
))}
)} {/* Related URLs */} {analysis.relatedUrls.length > 0 && (

Related Documentation

{analysis.relatedUrls.slice(0, 4).map((link, index) => ( {link.text} ({link.type}) ))}
)} {/* Generate Button */}
)}
{/* Instructions when no analysis */} {!analysis && !error && !isAnalyzing && (

Enter any documentation URL to analyze and generate install.md

Works with Mintlify, Docusaurus, GitBook, ReadMe, and more

)}
) }