import { useState, useEffect } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { Skeleton } from '@/components/ui/skeleton'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { AlertCircle } from 'lucide-react'; import type { DocContent as DocContentType } from './types'; interface DocContentProps { slug: string; } export default function DocContent({ slug }: DocContentProps) { const [doc, setDoc] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchDoc = async () => { setLoading(true); setError(null); try { const response = await fetch(`/wp-json/woonoow/v1/docs/${slug}`, { credentials: 'include', }); if (!response.ok) { throw new Error('Document not found'); } const data = await response.json(); if (data.success) { setDoc(data.doc); } else { throw new Error(data.message || 'Failed to load document'); } } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load document'); setDoc(null); } finally { setLoading(false); } }; fetchDoc(); }, [slug]); if (loading) { return (
); } if (error) { return ( {error} ); } if (!doc) { return null; } return (
(

{children}

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

{children}

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

{children}

), // Styled tables table: ({ children }) => (
{children}
), th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ), // Styled code blocks code: ({ className, children }) => { const isInline = !className; if (isInline) { return ( {children} ); } return ( {children} ); }, pre: ({ children }) => (
                            {children}
                        
), // Styled blockquotes for notes blockquote: ({ children }) => (
{children}
), // Links a: ({ href, children }) => ( {children} ), // Lists ul: ({ children }) => (
    {children}
), ol: ({ children }) => (
    {children}
), // Horizontal rule hr: () =>
, }} > {doc.content}
); }