/** Formatação compartilhada (moeda/data pt-BR) — Etapa 15 em diante. */ const currencyFormatter = new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL', }); const dateFormatter = new Intl.DateTimeFormat('pt-BR', { dateStyle: 'short' }); const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', { dateStyle: 'short', timeStyle: 'short' }); /** Aceita `string`/`number` (a API devolve `Decimal` do Prisma como string). */ export function formatCurrency(value: string | number | null | undefined): string { if (value === null || value === undefined) return '—'; const numeric = typeof value === 'string' ? Number(value) : value; if (Number.isNaN(numeric)) return '—'; return currencyFormatter.format(numeric); } export function formatDate(value: string | Date | null | undefined): string { if (!value) return '—'; const date = typeof value === 'string' ? new Date(value) : value; if (Number.isNaN(date.getTime())) return '—'; return dateFormatter.format(date); } export function formatDateTime(value: string | Date | null | undefined): string { if (!value) return '—'; const date = typeof value === 'string' ? new Date(value) : value; if (Number.isNaN(date.getTime())) return '—'; return dateTimeFormatter.format(date); }