import React, { useState } from 'react'; import { Check, Copy } from 'lucide-react'; import { useI18n } from '../application/i18n/I18nProvider'; import type { ShellHistoryEntry } from '../types'; import { Button } from './ui/button'; import { Input } from './ui/input'; // History Item Component interface HistoryItemProps { entry: ShellHistoryEntry; onSaveAsSnippet: (entry: ShellHistoryEntry, label: string) => void; onCopy: () => void; isCopied: boolean; } export const HistoryItem: React.FC = ({ entry, onSaveAsSnippet, onCopy, isCopied }) => { const { t } = useI18n(); const [isEditing, setIsEditing] = useState(false); const [label, setLabel] = useState(''); const handleSave = () => { if (label.trim()) { onSaveAsSnippet(entry, label); setIsEditing(false); setLabel(''); } }; const formatTime = (timestamp: number) => { const date = new Date(timestamp); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); const diffHours = Math.floor(diffMs / 3600000); const diffDays = Math.floor(diffMs / 86400000); if (diffMins < 1) return t('snippets.history.time.justNow'); if (diffMins < 60) return t('snippets.history.time.minutesAgo', { count: diffMins }); if (diffHours < 24) return t('snippets.history.time.hoursAgo', { count: diffHours }); if (diffDays < 7) return t('snippets.history.time.daysAgo', { count: diffDays }); return date.toLocaleDateString(); }; return (
{entry.command}
{entry.hostLabel} {t('snippets.history.separator')} {formatTime(entry.timestamp)}
{!isEditing && (
)}
{isEditing && (
setLabel(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSave()} autoFocus />
)}
); };