import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { ArrowLeft, Brain, Cpu, Loader2 } from 'lucide-react'; import ReactMarkdown from 'react-markdown'; // Import markdown content import linearRegressionMd from '../docs/linear_regression.md?raw'; import cnnMd from '../docs/cnn.md?raw'; const AlgorithmDetail: React.FC = () => { const { algorithmId } = useParams<{ algorithmId: string }>(); const navigate = useNavigate(); const [markdownContent, setMarkdownContent] = useState(''); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { loadMarkdownContent(); }, [algorithmId]); const loadMarkdownContent = async () => { try { setLoading(true); setError(null); let content = ''; switch (algorithmId) { case 'linear_regression': content = linearRegressionMd; break; case 'cnn': content = cnnMd; break; default: setError('Algorithm documentation not found'); setLoading(false); return; } setMarkdownContent(content); } catch (err) { setError('Failed to load algorithm documentation'); } finally { setLoading(false); } }; const getAlgorithmInfo = () => { switch (algorithmId) { case 'linear_regression': return { name: 'Linear Regression', category: 'Classical ML', icon: , categoryColor: 'bg-blue-100 text-blue-800' }; case 'cnn': return { name: 'Convolutional Neural Network', category: 'Deep Learning', icon: , categoryColor: 'bg-purple-100 text-purple-800' }; default: return { name: 'Unknown Algorithm', category: 'Unknown', icon: , categoryColor: 'bg-gray-100 text-gray-800' }; } }; const algorithmInfo = getAlgorithmInfo(); if (loading) { return (
Loading documentation...
); } if (error) { return (

Documentation Not Available

{error}

); } return (
{/* Algorithm Header */}
{algorithmInfo.icon}

{algorithmInfo.name}

{algorithmInfo.category}
{/* Markdown Content */}
(

{children}

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

{children}

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

{children}

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

{children}

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

{children}

), ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), code: ({ children, className }) => { const isBlock = className?.includes('language-'); if (isBlock) { return (
                          
                            {children}
                          
                        
    ); } return ( {children} ); }, blockquote: ({ children }) => (
    {children}
    ), strong: ({ children }) => ( {children} ), em: ({ children }) => ( {children} ), table: ({ children }) => (
    {children}
    ), thead: ({ children }) => ( {children} ), tbody: ({ children }) => ( {children} ), tr: ({ children }) => ( {children} ), th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ) }} > {markdownContent}
    ); }; export default AlgorithmDetail;