'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; interface SourceMessage { id: string; content: string; senderName: string | null; createdAt: string; } interface Draft { id: string; type: 'EVENT' | 'SEVA_TASK' | 'FAQ_ITEM'; status: string; proposedJson: Record; confidence: number | null; createdAt: string; sourceMessage: SourceMessage; } const TYPE_LABEL: Record = { EVENT: 'Event', SEVA_TASK: 'Seva Task', FAQ_ITEM: 'FAQ', }; const TYPE_COLOR: Record = { EVENT: 'bg-indigo-50 text-indigo-700 border-indigo-200', SEVA_TASK: 'bg-green-50 text-green-700 border-green-200', FAQ_ITEM: 'bg-amber-50 text-amber-700 border-amber-200', }; function ProposedPreview({ type, data }: { type: Draft['type']; data: Record }) { if (type === 'EVENT') { return (

Title: {data.title ?? '—'}

{data.date &&

Date: {data.date} {data.time ?? ''}

} {data.location &&

Location: {data.location}

} {data.description &&

Description: {data.description}

} {data.rsvpNeeded &&

RSVP required

} {data.sevaActionItems?.length > 0 && (

+{data.sevaActionItems.length} seva task(s) will also be created

)}
); } if (type === 'SEVA_TASK') { return (

Title: {data.title ?? '—'}

{data.parentEventTitle &&

Event: {data.parentEventTitle}

} {data.slots &&

Slots: {data.slots}

} {data.skills?.length > 0 &&

Skills: {data.skills.join(', ')}

}
); } return (

Q: {data.question ?? '—'}

A: {data.answer ?? '—'}

{data.tags?.length > 0 && (
{data.tags.map((t: string) => ( {t} ))}
)}
); } export function DraftCard({ draft }: { draft: Draft }) { const router = useRouter(); const [loading, setLoading] = useState<'approve' | 'reject' | null>(null); async function act(action: 'approve' | 'reject') { setLoading(action); try { await fetch(`/api/admin/drafts/${draft.id}/${action}`, { method: 'POST' }); router.refresh(); } finally { setLoading(null); } } const confidence = draft.confidence != null ? Math.round(draft.confidence * 100) : null; return (
{TYPE_LABEL[draft.type]} {confidence != null && ( {confidence}% confidence )}
{/* Source message */}

Source message{draft.sourceMessage.senderName ? ` — ${draft.sourceMessage.senderName}` : ''}

{draft.sourceMessage.content}

{/* AI proposed content */}

AI proposed

{/* Actions */}
); }