import React, { useState, useEffect } from 'react' import { Sparkles, Check, X, Clock, ChevronDown, ChevronUp } from 'lucide-react' import { useStoryStore } from '../../store/storyStore' import { useUIStore } from '../../store/uiStore' import { AISuggestion, SuggestionType } from '../../types' import { Button } from '../ui/Button' interface AISuggestionPanelProps { chapterId: number storyId?: number } const typeColors: Record = { grammar: 'bg-blue-500/20 text-blue-300 border-blue-500/30', style: 'bg-violet-500/20 text-violet-300 border-violet-500/30', plot: 'bg-amber-500/20 text-amber-300 border-amber-500/30', character: 'bg-emerald-500/20 text-emerald-300 border-emerald-500/30', pacing: 'bg-pink-500/20 text-pink-300 border-pink-500/30', } const SuggestionCard: React.FC<{ suggestion: AISuggestion onAccept: () => void onReject: () => void }> = ({ suggestion, onAccept, onReject }) => { const [expanded, setExpanded] = useState(false) return (
{suggestion.suggestion_type} {suggestion.accepted === true && ( Accepted )} {suggestion.accepted === false && ( Rejected )} {suggestion.accepted === null && ( Pending )}

Original:

"{suggestion.original_text}"

Suggested:

"{suggestion.suggested_text}"

{expanded && (

Explanation:

{suggestion.explanation}

{suggestion.applied_at && (

Applied: {new Date(suggestion.applied_at).toLocaleString()}

)}
)} {suggestion.accepted === null && (
)}
) } export const AISuggestionPanel: React.FC = ({ chapterId }) => { const { aiSuggestions, acceptSuggestion, rejectSuggestion, fetchSuggestions } = useStoryStore() const { addToast } = useUIStore() const [tab, setTab] = useState<'pending' | 'accepted' | 'rejected'>('pending') const [loading, setLoading] = useState(false) useEffect(() => { setLoading(true) fetchSuggestions(chapterId).finally(() => setLoading(false)) }, [chapterId]) // Backend already scopes results to this chapter via NEED_APPROVAL const chapterSuggestions = aiSuggestions const pending = chapterSuggestions.filter(s => s.accepted === null) const accepted = chapterSuggestions.filter(s => s.accepted === true) const rejected = chapterSuggestions.filter(s => s.accepted === false) const currentList = tab === 'pending' ? pending : tab === 'accepted' ? accepted : rejected return (

AI Writing Suggestions

{chapterSuggestions.length} total
{/* Tabs */}
{([ { key: 'pending', label: 'Pending', count: pending.length }, { key: 'accepted', label: 'Accepted', count: accepted.length }, { key: 'rejected', label: 'Rejected', count: rejected.length }, ] as const).map(t => ( ))}
{/* Suggestions */}
{loading ? (
Loading suggestions...
) : currentList.length === 0 ? (
No {tab} suggestions
) : ( currentList.map(s => ( { await acceptSuggestion(s.suggestion_id); addToast('Suggestion accepted!') }} onReject={async () => { await rejectSuggestion(s.suggestion_id); addToast('Suggestion rejected', 'info') }} /> )) )}
) }