import { format, parseISO } from "date-fns";
import { de } from "date-fns/locale";

export function formatDate(date: string | null | undefined, pattern = "dd.MM.yyyy"): string {
  if (!date) return "–";
  try {
    return format(parseISO(date), pattern, { locale: de });
  } catch {
    return date;
  }
}

export function formatDeadlineDate(date: string | null | undefined): string {
  return formatDate(date);
}

export function formatCurrency(amount: number | null | undefined, currency = "EUR"): string {
  if (amount === null || amount === undefined) {
    return "–";
  }
  return new Intl.NumberFormat("de-DE", { style: "currency", currency }).format(amount);
}
