/**
 * "18:20" → "6:20 PM". Times read AM/PM everywhere, in one format
 * (client 2026-11-16) — same as the frontend's formatTime12h. Storage
 * stays 24h; this feeds display text only (invoice, exports, messages,
 * audit). Empty for empty input; non-HH:MM values are echoed back.
 */
export function to12h(hhmm: string | null | undefined): string {
  if (!hhmm) return '';
  const m = /^(\d{1,2}):(\d{2})/.exec(String(hhmm).trim());
  if (!m) return String(hhmm);
  const h = Number(m[1]);
  return `${h % 12 || 12}:${m[2]} ${h >= 12 ? 'PM' : 'AM'}`;
}
