'use client'; import * as React from 'react'; import { Card } from '@/components/ui/Card'; import { Button } from '@/components/ui/Button'; import { EmptyState } from '@/components/ui/EmptyState'; import { History, X, Trash2, ChevronDown, ChevronUp, Clock } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; import { getHistory, clearHistory, removeHistoryItem, type HistoryItem } from '@/lib/storage/history'; export interface HistoryPanelProps { onSelectHistory: (item: HistoryItem) => void; className?: string; } export function HistoryPanel({ onSelectHistory, className }: HistoryPanelProps) { const [isExpanded, setIsExpanded] = React.useState(false); const [history, setHistory] = React.useState([]); const loadHistory = React.useCallback(() => { setHistory(getHistory()); }, []); React.useEffect(() => { loadHistory(); // Refresh history every 2 seconds when expanded if (isExpanded) { const interval = setInterval(loadHistory, 2000); return () => clearInterval(interval); } }, [isExpanded, loadHistory]); const handleClearAll = () => { clearHistory(); loadHistory(); }; const handleRemove = (id: string, e: React.MouseEvent) => { e.stopPropagation(); removeHistoryItem(id); loadHistory(); }; const formatTime = (timestamp: number) => { const now = Date.now(); const diff = now - timestamp; const minutes = Math.floor(diff / 60000); const hours = Math.floor(diff / 3600000); if (minutes < 1) return 'Just now'; if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; return new Date(timestamp).toLocaleDateString(); }; return (
{isExpanded && (
{history.length === 0 ? ( ) : ( <>
{history.map((item) => (
onSelectHistory(item)} className="group relative p-3 bg-muted/50 hover:bg-accent hover:scale-[1.02] rounded-md cursor-pointer transition-all" >
{item.font} {formatTime(item.timestamp)}

{item.text}

))}
)}
)}
); }