import React, { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { FolderOpen, Play, CheckCircle, Clock, AlertCircle, ArrowRight, RefreshCw, Zap, FileText, ChevronDown, ChevronUp, Target, Activity } from 'lucide-react'; import { useStudy } from '../context/StudyContext'; import { Study } from '../types'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; import { apiClient } from '../api/client'; const Home: React.FC = () => { const { studies, setSelectedStudy, refreshStudies, isLoading } = useStudy(); const [selectedPreview, setSelectedPreview] = useState(null); const [readme, setReadme] = useState(''); const [readmeLoading, setReadmeLoading] = useState(false); const [showAllStudies, setShowAllStudies] = useState(false); const navigate = useNavigate(); // Load README when a study is selected for preview useEffect(() => { if (selectedPreview) { loadReadme(selectedPreview.id); } else { setReadme(''); } }, [selectedPreview]); const loadReadme = async (studyId: string) => { setReadmeLoading(true); try { const response = await apiClient.getStudyReadme(studyId); setReadme(response.content || 'No README found for this study.'); } catch (error) { setReadme('No README found for this study.'); } finally { setReadmeLoading(false); } }; const handleSelectStudy = (study: Study) => { setSelectedStudy(study); navigate('/dashboard'); }; const getStatusIcon = (status: string) => { switch (status) { case 'running': return ; case 'completed': return ; case 'not_started': return ; default: return ; } }; const getStatusStyles = (status: string) => { switch (status) { case 'running': return { badge: 'bg-green-500/20 text-green-400 border-green-500/30', card: 'border-green-500/30 hover:border-green-500/50', glow: 'shadow-green-500/10' }; case 'completed': return { badge: 'bg-blue-500/20 text-blue-400 border-blue-500/30', card: 'border-blue-500/30 hover:border-blue-500/50', glow: 'shadow-blue-500/10' }; case 'not_started': return { badge: 'bg-dark-600 text-dark-400 border-dark-500', card: 'border-dark-600 hover:border-dark-500', glow: '' }; default: return { badge: 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30', card: 'border-yellow-500/30 hover:border-yellow-500/50', glow: 'shadow-yellow-500/10' }; } }; // Sort studies: running first, then by trial count const sortedStudies = [...studies].sort((a, b) => { if (a.status === 'running' && b.status !== 'running') return -1; if (b.status === 'running' && a.status !== 'running') return 1; return b.progress.current - a.progress.current; }); const displayedStudies = showAllStudies ? sortedStudies : sortedStudies.slice(0, 6); return (
{/* Header */}

Atomizer

FEA Optimization Platform

{/* Study Selection Section */}

Select a Study

{studies.length > 6 && ( )}
{isLoading ? (
Loading studies...
) : studies.length === 0 ? (

No studies found. Create a new study to get started.

) : (
{displayedStudies.map((study) => { const styles = getStatusStyles(study.status); const isSelected = selectedPreview?.id === study.id; return (
setSelectedPreview(study)} className={` relative p-4 rounded-xl border cursor-pointer transition-all duration-200 bg-dark-800 hover:bg-dark-750 ${styles.card} ${styles.glow} ${isSelected ? 'ring-2 ring-primary-500 border-primary-500' : ''} `} > {/* Status Badge */}

{study.name || study.id}

{study.id}

{getStatusIcon(study.status)} {study.status}
{/* Stats */}
{study.progress.current} trials
{study.best_value !== null && (
{study.best_value.toFixed(4)}
)}
{/* Progress Bar */}
{/* Selected Indicator */} {isSelected && (
)}
); })}
)}
{/* Study Documentation Section */} {selectedPreview && (
{/* Documentation Header */}

{selectedPreview.name || selectedPreview.id}

Study Documentation

{/* README Content */}
{readmeLoading ? (
Loading documentation...
) : (
(

{children}

), h2: ({ children }) => (

{children}

), h3: ({ children }) => (

{children}

), h4: ({ children }) => (

{children}

), // Paragraphs p: ({ children }) => (

{children}

), // Strong/Bold strong: ({ children }) => ( {children} ), // Links a: ({ href, children }) => ( {children} ), // Lists ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), // Code blocks with syntax highlighting code: ({ inline, className, children, ...props }: any) => { const match = /language-(\w+)/.exec(className || ''); const language = match ? match[1] : ''; if (!inline && language) { return (
    {language}
    {String(children).replace(/\n$/, '')}
    ); } if (!inline) { return (
                                    {children}
                                  
    ); } return ( {children} ); }, // Tables table: ({ children }) => (
    {children}
    ), thead: ({ children }) => ( {children} ), tbody: ({ children }) => ( {children} ), tr: ({ children }) => ( {children} ), th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ), // Blockquotes blockquote: ({ children }) => (
    {children}
    ), // Horizontal rules hr: () => (
    ), // Images img: ({ src, alt }) => ( {alt} ), }} > {readme}
    )}
    )} {/* Empty State when no study selected */} {!selectedPreview && studies.length > 0 && (

    Select a study to view its documentation

    Click on any study card above

    )}
    ); }; export default Home;