export const statusLabel = (status: string) =>
    ({
        draft: 'Brouillon',
        sent: 'Envoyée',
        closed: 'Fermée',
        cancelled: 'Annulée',
        pending: 'En attente',
        viewed: 'Consultée',
        responded: 'Réponse reçue',
    })[status] ?? status;
export function formatDate(value?: string | null) {
    if (!value) {
        return '—';
    }

    const date = new Date(value);

    return Number.isNaN(date.getTime())
        ? '—'
        : new Intl.DateTimeFormat('fr-CA', {
              dateStyle: 'medium',
              timeStyle: 'short',
              timeZone: 'America/Toronto',
          }).format(date);
}
export function currency(value?: number | string | null) {
    return value == null
        ? '—'
        : new Intl.NumberFormat('fr-CA', {
              style: 'currency',
              currency: 'CAD',
          }).format(Number(value));
}
export function toTorontoInput(value?: string | null) {
    if (!value) {
        return '';
    }

    const parts = new Intl.DateTimeFormat('en-CA', {
        timeZone: 'America/Toronto',
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        hourCycle: 'h23',
    }).formatToParts(new Date(value));
    const get = (type: string) =>
        parts.find((p) => p.type === type)?.value ?? '';

    return `${get('year')}-${get('month')}-${get('day')}T${get('hour')}:${get('minute')}`;
}
