// src/renderer/components/shared/HistoryEntryCard.tsx // High-End Agency Dictation History Card with Audio Telemetry & Instant Actions import React, { useState, useEffect, useCallback } from 'react' import { Box, IconButton, Tooltip, Chip, Collapse } from '@mui/material' import { Copy, Check, Trash2, Tag, X, ScrollText, ChevronDown, Sparkles, Volume2, Star } from 'lucide-react' import { MetalCard, Led, TactileBadge } from '@d3ro/ui/components/ds' import { d3roPalette, d3roFontSans, d3roFontMono, d3roTypo, d3roRadius, d3roShadow } from '@d3ro/ui/theme' import { useI18n } from '@d3ro/i18n' import { formatDuration } from '../../utils/formatters' import { isImeComposingEvent } from '../../utils/keyboard' import type { HistoryEntry, MemoTag, MeetingSummaryResult } from '@d3ro/core/types' export interface HistoryEntryCardProps { entry: HistoryEntry onCopy?: (text: string) => void onDelete?: (id: string) => void /** 즐겨찾기 토글 — 모바일·웹과 공유되는 값 */ onToggleFavorite?: (entry: HistoryEntry) => void showTags?: boolean onTagClick?: (tag: string) => void } export function HistoryEntryCard({ entry, onCopy, onDelete, onToggleFavorite, showTags = false, onTagClick, }: HistoryEntryCardProps): React.ReactElement { const { t, formatTime } = useI18n() const displayText = entry.polishedText || entry.originalText const isPolished = Boolean(entry.polishedText) const [tags, setTags] = useState([]) const [tagInput, setTagInput] = useState('') const [showTagInput, setShowTagInput] = useState(false) const [summaryExpanded, setSummaryExpanded] = useState(false) const [summary, setSummary] = useState(null) const [summaryLoading, setSummaryLoading] = useState(false) const [copied, setCopied] = useState(false) const hasSummary = !!entry.summaryText const loadTags = useCallback(async () => { if (!showTags) return const result = await window.electronAPI.memo.getTags(entry.id) if (result.success) setTags(result.data) }, [entry.id, showTags]) useEffect(() => { loadTags() }, [loadTags]) const handleCopyClick = (e: React.MouseEvent) => { e.stopPropagation() onCopy?.(displayText) setCopied(true) setTimeout(() => setCopied(false), 1500) } const handleAddTag = useCallback(async () => { const trimmed = tagInput.trim() if (!trimmed) return const result = await window.electronAPI.memo.addTag(entry.id, trimmed) if (result.success) { setTags((prev) => [...prev, result.data]) setTagInput('') setShowTagInput(false) } }, [entry.id, tagInput]) const handleRemoveTag = useCallback( async (tag: string) => { const result = await window.electronAPI.memo.removeTag(entry.id, tag) if (result.success) { setTags((prev) => prev.filter((t) => t.tag !== tag)) } }, [entry.id], ) const handleTagKeyDown = useCallback( (e: React.KeyboardEvent) => { if (isImeComposingEvent(e)) return if (e.key === 'Enter') { e.preventDefault() handleAddTag() } if (e.key === 'Escape') { setShowTagInput(false) setTagInput('') } }, [handleAddTag], ) const handleToggleSummary = useCallback( async (e: React.MouseEvent) => { e.stopPropagation() if (summaryExpanded) { setSummaryExpanded(false) return } setSummaryExpanded(true) if (!summary) { setSummaryLoading(true) const result = await window.electronAPI.meetingSummary.getSummary({ historyId: entry.id }) if (result.success && result.data) { setSummary(result.data) } setSummaryLoading(false) } }, [summaryExpanded, summary, entry.id], ) return ( {/* Status Indicator Bead */} {/* Header Row: Title + Timestamp + Action Icons */} {entry.title ?? displayText.slice(0, 50)} {isPolished && ( )} {/* Quick Action Buttons */} {onToggleFavorite && ( { e.stopPropagation() onToggleFavorite(entry) }} sx={{ p: 0.6, color: entry.isFavorite ? d3roPalette.tag.orange : d3roPalette.text.inactive, bgcolor: entry.isFavorite ? d3roPalette.tag.orangeBg : 'transparent', '&:hover': { color: d3roPalette.tag.orange, bgcolor: d3roPalette.tag.orangeBg }, }} > )} {copied ? : } {onDelete && ( { e.stopPropagation() onDelete(entry.id) }} sx={{ p: 0.6, color: d3roPalette.text.inactive, '&:hover': { color: d3roPalette.tag.red, bgcolor: d3roPalette.tag.redBg }, }} > )} {/* Transcript Content Preview */} {displayText} {/* Metadata Telemetry Badges */} {formatTime(entry.createdAt)} {formatDuration(entry.duration)} {entry.detectedLanguage && ( {entry.detectedLanguage.toUpperCase()} )} {hasSummary && ( {t('meetingSummary.title')} )} {/* Tags Row */} {showTags && ( {tags.map((tag) => ( onTagClick?.(tag.tag)} onDelete={() => handleRemoveTag(tag.tag)} deleteIcon={} sx={{ height: 20, fontFamily: d3roFontMono, fontSize: '10.5px', bgcolor: d3roPalette.tag.purpleBg, color: d3roPalette.tag.purple, borderRadius: d3roRadius.pill, '& .MuiChip-deleteIcon': { color: d3roPalette.tag.purple, fontSize: 11 }, '&:hover': { bgcolor: d3roPalette.tag.purple, color: d3roPalette.text.inverse }, }} /> ))} {showTagInput ? ( ) => setTagInput(e.target.value)} onKeyDown={handleTagKeyDown} onBlur={() => { if (!tagInput.trim()) setShowTagInput(false) }} autoFocus placeholder={t('memo.tagPlaceholder')} sx={{ border: `1px solid ${d3roPalette.accent.main}`, bgcolor: d3roPalette.bg.input, color: d3roPalette.text.primary, fontFamily: d3roFontMono, fontSize: '11px', px: 1, py: 0.25, borderRadius: d3roRadius.pill, outline: 'none', width: 90, }} /> ) : ( setShowTagInput(true)} sx={{ p: 0.4, color: d3roPalette.text.inactive, bgcolor: d3roPalette.bg.inset, borderRadius: '50%', '&:hover': { color: d3roPalette.accent.light, bgcolor: d3roPalette.glass.raised }, }} > )} )} {/* Expandable Meeting Summary Box */} {summaryLoading ? ( {t('common.loading')}... ) : summary ? ( {summary.summaryText} ) : ( {entry.summaryText || t('meetingSummary.empty')} )} ) }