"use client" import { useEffect, useState, Suspense } from "react" import { useRouter, useSearchParams } from "next/navigation" import Link from "next/link" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Progress } from "@/components/ui/progress" import { ArrowLeft, Brain, Code, FileText, GitBranch, Star, Shield, TrendingUp, AlertTriangle, CheckCircle, Clock, Zap, Target, BarChart3, Layers, Cpu, Search, File, Folder, Eye, AlertCircle } from "lucide-react" interface FileAnalysis { id: string name: string path: string type: 'file' | 'folder' status: 'scanning' | 'analyzing' | 'completed' | 'pending' size?: string language?: string issues?: number score?: number details?: string } // Component that uses useSearchParams - needs to be wrapped in Suspense function AIAnalysisContent() { const router = useRouter() const searchParams = useSearchParams() const repoId = searchParams.get('repoId') const repoName = searchParams.get('repoName') || 'Repository' const [analysisProgress, setAnalysisProgress] = useState(0) const [isAnalyzing, setIsAnalyzing] = useState(true) const [currentFile, setCurrentFile] = useState('Initializing analysis...') const [files, setFiles] = useState([ { id: '1', name: 'package.json', path: '/package.json', type: 'file', status: 'pending', language: 'JSON', size: '2.1 KB' }, { id: '2', name: 'src', path: '/src', type: 'folder', status: 'pending' }, { id: '3', name: 'App.js', path: '/src/App.js', type: 'file', status: 'pending', language: 'JavaScript', size: '5.2 KB' }, { id: '4', name: 'components', path: '/src/components', type: 'folder', status: 'pending' }, { id: '5', name: 'Header.jsx', path: '/src/components/Header.jsx', type: 'file', status: 'pending', language: 'JavaScript', size: '3.8 KB' }, { id: '6', name: 'Footer.jsx', path: '/src/components/Footer.jsx', type: 'file', status: 'pending', language: 'JavaScript', size: '2.5 KB' }, { id: '7', name: 'utils', path: '/src/utils', type: 'folder', status: 'pending' }, { id: '8', name: 'helpers.js', path: '/src/utils/helpers.js', type: 'file', status: 'pending', language: 'JavaScript', size: '4.1 KB' }, { id: '9', name: 'README.md', path: '/README.md', type: 'file', status: 'pending', language: 'Markdown', size: '1.8 KB' }, { id: '10', name: 'styles', path: '/styles', type: 'folder', status: 'pending' }, { id: '11', name: 'main.css', path: '/styles/main.css', type: 'file', status: 'pending', language: 'CSS', size: '6.3 KB' }, { id: '12', name: 'tests', path: '/tests', type: 'folder', status: 'pending' }, { id: '13', name: 'App.test.js', path: '/tests/App.test.js', type: 'file', status: 'pending', language: 'JavaScript', size: '2.9 KB' } ]) useEffect(() => { if (!repoId) { router.push('/github/repos') return } let fileIndex = 0 let progress = 0 const interval = setInterval(() => { if (fileIndex < files.length) { const currentFileData = files[fileIndex] // Update current file being analyzed setCurrentFile(`Analyzing ${currentFileData.name}...`) // Update file status to scanning setFiles(prev => prev.map((file, index) => index === fileIndex ? { ...file, status: 'scanning' as const } : file )) // After a short delay, mark as analyzing setTimeout(() => { setFiles(prev => prev.map((file, index) => index === fileIndex ? { ...file, status: 'analyzing' as const } : file )) }, 500) // After another delay, mark as completed with mock data setTimeout(() => { setFiles(prev => prev.map((file, index) => index === fileIndex ? { ...file, status: 'completed' as const, score: Math.floor(Math.random() * 30) + 70, // 70-100 issues: Math.floor(Math.random() * 5), details: file.type === 'file' ? 'Analysis completed successfully' : 'Directory scanned' } : file )) }, 1000) progress = Math.min(100, ((fileIndex + 1) / files.length) * 100) setAnalysisProgress(progress) fileIndex++ } else { // Complete analysis setIsAnalyzing(false) setCurrentFile('Analysis completed!') setAnalysisProgress(100) clearInterval(interval) } }, 1500) return () => clearInterval(interval) }, [repoId, router, files.length]) const getStatusIcon = (status: FileAnalysis['status'], type: FileAnalysis['type']) => { switch (status) { case 'completed': return case 'analyzing': return
case 'scanning': return case 'pending': return } } const getFileIcon = (type: FileAnalysis['type'], language?: string) => { if (type === 'folder') { return } switch (language) { case 'JavaScript': return case 'CSS': return case 'Markdown': return case 'JSON': return default: return } } const getScoreColor = (score: number) => { if (score >= 90) return 'text-green-400' if (score >= 80) return 'text-yellow-400' if (score >= 70) return 'text-orange-400' return 'text-red-400' } return (
{/* Header */}

AI Code Analysis

Analyzing: {repoName}

{/* Analysis Progress */} {isAnalyzing && (

Analysis Progress

{Math.round(analysisProgress)}%

{currentFile}

)} {/* File Analysis List */} File Analysis Results
{files.map((file) => (
{getFileIcon(file.type, file.language)}
{file.name} {file.language && ( {file.language} )} {file.size && ( {file.size} )}

{file.path}

{file.status === 'completed' && file.score && (
{file.issues && file.issues > 0 && (
{file.issues}
)} {file.score}/100
)} {getStatusIcon(file.status, file.type)}
{file.status === 'completed' && file.details && (
{file.details}
)}
))}
{/* Summary */} {!isAnalyzing && ( Analysis Summary
{files.filter(f => f.status === 'completed').length}
Files Analyzed
{files.filter(f => f.language).length}
Languages Found
{files.reduce((sum, f) => sum + (f.issues || 0), 0)}
Issues Found
{Math.round(files.filter(f => f.score).reduce((sum, f) => sum + (f.score || 0), 0) / files.filter(f => f.score).length) || 0}
Avg Score
)} {/* Action Buttons */} {!isAnalyzing && (
)}
) } export default function AIAnalysisPage() { return (
Loading analysis...
}> ) }