export function extractErrorMessage(err: unknown, fallback: string): string {
  if (typeof err === "object" && err !== null) {
    const e = err as Record<string, unknown>
    if (typeof e.data === "object" && e.data !== null) {
      const d = e.data as Record<string, unknown>
      if (typeof d.error_message === "string") return d.error_message
      if (typeof d.message === "string") return d.message
    }
    if (typeof e.error === "string") return e.error
  }
  return fallback
}

export function formatDate(dateString: string): string {
  return new Intl.DateTimeFormat("fr-FR", {
    day: "2-digit",
    month: "short",
    year: "numeric",
  }).format(new Date(dateString))
}
