import type { CSSProperties } from 'react'; import type { NotificationItem, NotificationKind } from './types.js'; export interface InboxItemProps { item: NotificationItem; /** Called when the item body is clicked. */ onSelect?: (item: NotificationItem) => void; /** Mark this single item as read. */ onMarkRead?: (id: string) => void; /** Dense layout (smaller padding, smaller font). */ dense?: boolean; className?: string; style?: CSSProperties; } /** * `` — single notification row. Used inside `` * but also exported for products that build custom inbox surfaces. */ export function InboxItem({ item, onSelect, onMarkRead, dense, className, style, }: InboxItemProps) { const tone = TONE[item.kind ?? 'info']; const padding = dense ? '6px 10px' : 'var(--bl-space-2, 8px) var(--bl-space-3, 12px)'; return (
{/* Unread dot */} {/* Avatar / kind icon */} {item.icon ?? tone.glyph}
{item.actions && item.actions.length > 0 && (
{item.actions.map(a => ( ))}
)}
); } const TONE: Record = { info: { dot: 'var(--bl-info, #38bdf8)', iconBg: 'var(--bl-info-muted, rgba(56,189,248,0.18))', iconFg: 'var(--bl-info, #38bdf8)', glyph: 'i', }, success: { dot: 'var(--bl-success, #22c55e)', iconBg: 'var(--bl-success-muted, rgba(34,197,94,0.18))', iconFg: 'var(--bl-success, #22c55e)', glyph: '✓', }, warning: { dot: 'var(--bl-warning, #f59e0b)', iconBg: 'var(--bl-warning-muted, rgba(245,158,11,0.18))', iconFg: 'var(--bl-warning, #f59e0b)', glyph: '!', }, danger: { dot: 'var(--bl-danger, #ef4444)', iconBg: 'var(--bl-danger-muted, rgba(239,68,68,0.18))', iconFg: 'var(--bl-danger, #ef4444)', glyph: '✕', }, mention: { dot: 'var(--bl-accent, #6366f1)', iconBg: 'var(--bl-accent-muted, rgba(99,102,241,0.18))', iconFg: 'var(--bl-accent, #6366f1)', glyph: '@', }, }; function relativeTime(input: string | Date): string { const d = typeof input === 'string' ? new Date(input) : input; const diff = (Date.now() - d.getTime()) / 1000; if (diff < 60) return 'just now'; if (diff < 3600) return `${Math.floor(diff / 60)}m ago`; if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`; if (diff < 86400 * 7) return `${Math.floor(diff / 86400)}d ago`; return d.toLocaleDateString(); }