/** Montants stockés en centimes. */
export const formatMoney = (
    cents: number | null | undefined,
    currency: string | null | undefined,
): string =>
    new Intl.NumberFormat('fr-FR', {
        style: 'currency',
        currency: currency || 'EUR',
    }).format((cents ?? 0) / 100);

export const formatDate = (value: string | null | undefined): string =>
    value
        ? new Intl.DateTimeFormat('fr-FR', { dateStyle: 'medium' }).format(
              new Date(value),
          )
        : '—';

export const formatDateTime = (value: string | null | undefined): string =>
    value
        ? new Intl.DateTimeFormat('fr-FR', {
              dateStyle: 'medium',
              timeStyle: 'short',
          }).format(new Date(value))
        : '—';

export const formatNumber = (value: number | null | undefined): string =>
    new Intl.NumberFormat('fr-FR').format(value ?? 0);
