import { PRIORITY_COLORS } from '../../shared/constants'; import { fmtTime } from '../../shared/time'; import { esc } from '../dom'; import { icon } from '../icons'; import { state, type FbComment } from '../state'; export function renderCard(c: FbComment): string { const isOwn = c.author === state.username; const pc = PRIORITY_COLORS[c.priority] || PRIORITY_COLORS.want; let h = '
'; h += '
'; h += '
' + esc(c.author.charAt(0)) + '
'; h += '' + esc(c.author) + ''; h += '' + fmtTime(c.timestamp) + ''; if (c.resolved) h += '' + icon('check', 12) + ' 解決済'; h += '
'; h += '' + esc(c.priority.charAt(0).toUpperCase() + c.priority.slice(1)) + ''; h += '
'; if (c.quote) { const q = c.quote.length > 100 ? c.quote.substring(0, 100) + '...' : c.quote; h += '
' + esc(q) + '
'; } if (state.editingId === c.id) { h += '
'; h += '
'; (['must', 'better', 'want'] as const).forEach((p) => { const sel = state.editPriority === p; const pc2 = PRIORITY_COLORS[p]; h += ''; }); h += '
'; h += ''; h += '
'; h += '
'; } else { h += '
' + esc(c.content) + '
'; } if (state.editingId !== c.id) { h += '
'; h += ''; h += ''; if (isOwn) h += ''; if (isOwn) h += ''; h += '
'; } const replies = state.comments.filter((r) => r.parentId === c.id).sort((a, b) => a.timestamp - b.timestamp); if (replies.length > 0) { h += '
'; replies.forEach((r) => { const isOwnReply = r.author === state.username; h += '
' + esc(r.author.charAt(0)) + '
' + esc(r.author) + ' · ' + fmtTime(r.timestamp) + '
'; if (state.editingId === r.id) { h += '
'; } else { h += '
' + esc(r.content) + '
'; h += '
'; h += ''; if (isOwnReply) h += ''; if (isOwnReply) h += ''; h += '
'; } h += '
'; }); h += '
'; } if (state.replyingTo === c.id) { h += '
'; } h += '
'; return h; }