'use client' import * as React from 'react' import { GitPullRequestArrow, Calendar } from 'lucide-react' import { cn } from '@open-mercato/shared/lib/utils' import { formatRelativeTime } from '@open-mercato/shared/lib/time' import { useLocale, useT } from '@open-mercato/shared/lib/i18n/context' import type { NotificationRendererProps } from '@open-mercato/shared/modules/notifications/types' type ChangeRow = { field: string incoming: string current: string } function parseRows(notification: NotificationRendererProps['notification']): ChangeRow[] { const raw = notification.bodyVariables?.changedRowsJson if (!raw || typeof raw !== 'string') return [] try { const parsed = JSON.parse(raw) if (!Array.isArray(parsed)) return [] return parsed .filter((row): row is ChangeRow => ( row && typeof row === 'object' && typeof (row as ChangeRow).field === 'string' && typeof (row as ChangeRow).incoming === 'string' && typeof (row as ChangeRow).current === 'string' )) .slice(0, 12) } catch { return [] } } export function IncomingChangesRenderer({ notification }: NotificationRendererProps) { const t = useT() const locale = useLocale() const rows = React.useMemo(() => parseRows(notification), [notification]) const isUnread = notification.status === 'unread' return (
{isUnread ? (
) : null}

{notification.title}

{formatRelativeTime(notification.createdAt, { locale, translate: t }) ?? ''}
{rows.length ? rows.map((row, index) => ( )) : ( )}
{t('record_locks.conflict.field', 'Field')} {t('record_locks.conflict.incoming_label', 'Incoming')} {t('record_locks.conflict.current_label', 'Current')}
{row.field} {row.incoming} {row.current}
{t('record_locks.conflict.no_field_details', 'Field-level conflict details are unavailable for this record. Choose a resolution to continue.')}
) } export default IncomingChangesRenderer