'use client'; import type { Order, OrderStatus } from 'brainerce'; import { useTranslations } from '@/core/lib/translations'; import { cn } from '@/core/lib/utils'; /** * Message key for every order status the API can return. * * The API sends these values UPPERCASE and verbatim (`PENDING`, `ON_HOLD`, * ...). Never lowercase them before the lookup: a lowercase key silently * misses and every row falls through to the default label. */ export type OrderStatusLabelKey = | 'statusDraft' | 'statusPending' | 'statusProcessing' | 'statusOnHold' | 'statusPaid' | 'statusShipped' | 'statusDelivered' | 'statusCompleted' | 'statusFulfilled' | 'statusCancelled' | 'statusRefunded' | 'statusPartiallyRefunded'; export const ORDER_STATUS_LABEL_KEYS: Record = { DRAFT: 'statusDraft', PENDING: 'statusPending', PROCESSING: 'statusProcessing', ON_HOLD: 'statusOnHold', PAID: 'statusPaid', SHIPPED: 'statusShipped', DELIVERED: 'statusDelivered', COMPLETED: 'statusCompleted', FULFILLED: 'statusFulfilled', CANCELLED: 'statusCancelled', REFUNDED: 'statusRefunded', PARTIALLY_REFUNDED: 'statusPartiallyRefunded', }; interface OrderStatusTimelineProps { history: Order['statusHistory']; className?: string; } export function OrderStatusTimeline({ history, className }: OrderStatusTimelineProps) { const t = useTranslations('account'); if (!history || history.length === 0) return null; return (

{t('statusTimeline')}

    {history.map((entry, idx) => { const key = ORDER_STATUS_LABEL_KEYS[entry.status] || 'statusPending'; const when = new Date(entry.at); const whenStr = isNaN(when.getTime()) ? entry.at : when.toLocaleString(undefined, { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', }); return (
  1. {t(key)} ยท {whenStr} {entry.note && ({entry.note})}
  2. ); })}
); }