const DATE_RE =
  /^\d{4}-\d{2}-\d{2}([ T]\d{2}:\d{2}(:\d{2}(\.\d+)?(Z|[+-]\d{2}:?\d{2})?)?)?$/;

export function formatDateTime(value: string | null | undefined): string {
  if (!value) {
    return "—";
  }
  if (!DATE_RE.test(value)) {
    return value;
  }
  const d = new Date(value.replace(" ", "T"));
  if (isNaN(d.getTime())) {
    return value;
  }
  const hasTime = value.length > 10;
  return new Intl.DateTimeFormat("nl-NL", {
    dateStyle: "medium",
    ...(hasTime ? { timeStyle: "short" } : {}),
  }).format(d);
}
