'use client'; import { getGlobalReplaySystem } from '@/lib/infrastructure/ErrorReplay'; import { Button } from '@/ui/Button'; import { Icon } from '@/ui/Icon'; import { IconButton } from '@/ui/IconButton'; import { Stack } from '@/ui/primitives/Stack'; import { Text } from '@/ui/Text'; import { Box, Clock, Copy, Download, Play, Trash2 } from 'lucide-react'; import { useEffect, useState } from 'react'; interface ReplayEntry { id: string; timestamp: string; error: string; type: string; } export function ReplaySection() { const [replays, setReplays] = useState([]); const [loading, setLoading] = useState(false); useEffect(() => { loadReplays(); }, []); const loadReplays = () => { const system = getGlobalReplaySystem(); const index = system.getReplayIndex(); setReplays(index); }; const handleReplay = async (replayId: string) => { setLoading(true); try { const system = getGlobalReplaySystem(); await system.replay(replayId); } catch (error) { console.error('Replay failed:', error); } finally { setLoading(false); } }; const handleExport = (replayId: string) => { const system = getGlobalReplaySystem(); const data = system.exportReplay(replayId, 'json'); const blob = new Blob([data], { type: 'application/json' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `replay_${replayId}.json`; a.click(); URL.revokeObjectURL(url); }; const handleCopy = async (replayId: string) => { const system = getGlobalReplaySystem(); const data = system.exportReplay(replayId, 'json'); try { await navigator.clipboard.writeText(data); console.log('Replay data copied to clipboard'); } catch (err) { console.error('Failed to copy:', err); } }; const handleDelete = (replayId: string) => { if (confirm('Delete this replay?')) { const system = getGlobalReplaySystem(); system.deleteReplay(replayId); loadReplays(); } }; const handleClearAll = () => { if (confirm('Clear all replays?')) { const system = getGlobalReplaySystem(); system.clearAll(); loadReplays(); } }; return ( Error Replay {replays.length === 0 ? ( No replays available ) : ( {replays.map((replay) => ( {replay.type} {replay.error} {new Date(replay.timestamp).toLocaleTimeString()} handleDelete(replay.id)} variant="secondary" size="sm" /> ))} )} ); }