'use client'; import { useState, useEffect } from 'react'; import { Brain, Clock, Heart, BookOpen, Sparkles, ChevronRight, RefreshCw } from 'lucide-react'; interface Episode { id: string; content: string; insight: string; emotion: string; timestamp: string; type: 'conversation' | 'reflection' | 'prayer' | 'scripture'; } const emotionColors: Record = { joy: { bg: 'bg-amber-500/10', text: 'text-amber-400', border: 'border-amber-500/30' }, peace: { bg: 'bg-emerald-500/10', text: 'text-emerald-400', border: 'border-emerald-500/30' }, hope: { bg: 'bg-blue-500/10', text: 'text-blue-400', border: 'border-blue-500/30' }, gratitude: { bg: 'bg-purple-500/10', text: 'text-purple-400', border: 'border-purple-500/30' }, seeking: { bg: 'bg-violet-500/10', text: 'text-violet-400', border: 'border-violet-500/30' }, sorrow: { bg: 'bg-rose-500/10', text: 'text-rose-400', border: 'border-rose-500/30' }, neutral: { bg: 'bg-neutral-500/10', text: 'text-neutral-400', border: 'border-neutral-500/30' }, }; const typeIcons = { conversation: Brain, reflection: Sparkles, prayer: Heart, scripture: BookOpen, }; // Mock data - in production this would come from the API const mockEpisodes: Episode[] = [ { id: '1', content: 'Asked about dealing with anxiety and finding peace', insight: 'Seeking comfort through Scripture - Philippians 4:6-7 resonated', emotion: 'seeking', timestamp: new Date(Date.now() - 1000 * 60 * 30).toISOString(), type: 'conversation', }, { id: '2', content: 'Morning prayer for guidance in career decision', insight: 'Trust in divine timing while taking practical steps', emotion: 'hope', timestamp: new Date(Date.now() - 1000 * 60 * 60 * 2).toISOString(), type: 'prayer', }, { id: '3', content: 'Studied Psalm 23 with ORA', insight: 'The shepherd metaphor connects protection with provision', emotion: 'peace', timestamp: new Date(Date.now() - 1000 * 60 * 60 * 24).toISOString(), type: 'scripture', }, { id: '4', content: 'Journaled about gratitude for community', insight: 'Fellowship strengthens faith during difficult seasons', emotion: 'gratitude', timestamp: new Date(Date.now() - 1000 * 60 * 60 * 48).toISOString(), type: 'reflection', }, ]; function formatTimeAgo(timestamp: string): string { const now = new Date(); const date = new Date(timestamp); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / (1000 * 60)); const hours = Math.floor(diff / (1000 * 60 * 60)); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; if (days === 1) return 'Yesterday'; if (days < 7) return `${days}d ago`; return date.toLocaleDateString(); } interface MemoryTimelineProps { compact?: boolean; maxItems?: number; } export default function MemoryTimeline({ compact = false, maxItems = 5 }: MemoryTimelineProps) { const [episodes, setEpisodes] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchEpisodes = async () => { setLoading(true); setError(null); try { // Try to fetch from backend const response = await fetch('http://localhost:6000/api/memory/episodes', { method: 'GET', headers: { 'Content-Type': 'application/json' }, }); if (response.ok) { const data = await response.json(); setEpisodes(data.episodes || []); } else { // Use mock data if API not available setEpisodes(mockEpisodes); } } catch { // Use mock data on error setEpisodes(mockEpisodes); } finally { setLoading(false); } }; useEffect(() => { fetchEpisodes(); }, []); const displayEpisodes = episodes.slice(0, maxItems); if (compact) { return (
Recent Memories
{loading ? (
{[1, 2, 3].map((i) => (
))}
) : (
{displayEpisodes.map((episode) => { const colors = emotionColors[episode.emotion] || emotionColors.neutral; const Icon = typeIcons[episode.type]; return (

{episode.content}

{episode.emotion} {formatTimeAgo(episode.timestamp)}
); })}
)}
); } return (
{/* Header */}

Episodic Memory

Your spiritual journey timeline

{/* Timeline */}
{loading ? (
{[1, 2, 3, 4].map((i) => (
))}
) : error ? (

{error}

) : episodes.length === 0 ? (

No memories yet

Start a conversation to build your spiritual memory

) : (
{/* Timeline line */}
{/* Episodes */}
{displayEpisodes.map((episode, index) => { const colors = emotionColors[episode.emotion] || emotionColors.neutral; const Icon = typeIcons[episode.type]; return (
{/* Timeline dot */}
{/* Card */}

{episode.content}

"{episode.insight}"

{episode.emotion} {formatTimeAgo(episode.timestamp)}
); })}
)}
{/* Footer */} {episodes.length > maxItems && (
)}
); }