'use client'; import { useChatStore } from '@/store/use-chat'; import { MessageCircle, Check } from 'lucide-react'; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription } from '@/components/ui/sheet'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import rehypeHighlight from 'rehype-highlight'; import rehypeRaw from 'rehype-raw'; export function DraftSheet() { const { phase, currentDraft, setPhase, resetSession, sessionId } = useChatStore(); const isOpen = phase === 'review' && !!currentDraft; const handleAccept = async () => { if (!currentDraft) return; if (!sessionId) { console.error("No active session ID"); return; } try { const { DraftService } = await import('@/lib/db/draft-service'); await DraftService.saveDraft({ sessionId, title: currentDraft.title, content: currentDraft.lesson, createdAt: Date.now(), status: 'completed', completedAt: Date.now(), tags: currentDraft.keywords || [] }); // Close conversation and redirect to homepage resetSession(); window.location.href = '/'; } catch (error) { console.error("Failed to save draft:", error); } }; const handleResume = () => { // Close the sheet and go back to chat setPhase('elicitation'); }; if (!currentDraft) return null; // Convert DraftArtifact to Draft-like format for consistent rendering const draftLike = { title: currentDraft.title, content: currentDraft.lesson, tags: currentDraft.keywords || [] }; return ( !open && handleResume()}> Draft Review Review your draft before saving
{/* Title */}

{currentDraft.title}

{/* Insight */} {currentDraft.insight && (

"{currentDraft.insight}"

)} {/* Body content - Markdown with prose styling */}
(

), h2: ({ node, ...props }) => (

), h3: ({ node, ...props }) => (

), p: ({ node, ...props }) => (

), code: ({ node, inline, className, children, ...props }: any) => { if (inline) { return ( {children} ); } return ( {children} ); }, pre: ({ node, ...props }) => (

                                ),
                                a: ({ node, ...props }) => (
                                    
                                ),
                                ul: ({ node, ...props }) => (
                                    
    ), ol: ({ node, ...props }) => (
      ), blockquote: ({ node, ...props }) => (
      ), }} > {currentDraft.lesson}

{/* Keywords/Tags */} {currentDraft.keywords && currentDraft.keywords.length > 0 && (
{currentDraft.keywords.map((keyword, index) => ( #{keyword} ))}
)}
{/* Footer with buttons */}
); }