/**
 * Shared formatting utilities used across the native app.
 */

/** EUR formatter instance shared by both formatEur variants. */
const eurFormatter = new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" });

/**
 * Formats a number as EUR currency using German locale.
 * Uses Math.abs by default — callers add +/- signs where needed.
 * Pass `absolute: false` to preserve the original sign.
 */
export function formatEur(amount: number, absolute = true): string {
  return eurFormatter.format(absolute ? Math.abs(amount) : amount);
}

/**
 * Formats an ISO date string for display.
 * Returns "Heute" / "Today" for today, otherwise "D. MonthName".
 */
export function formatDateDisplay(isoDate: string, language: string, todayLabel: string): string {
  const today = new Date();
  const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, "0")}-${String(today.getDate()).padStart(2, "0")}`;
  if (isoDate.startsWith(todayStr)) return todayLabel;
  const d = new Date(isoDate);
  const locale = language === "en" ? "en-US" : "de-DE";
  const monthName = new Intl.DateTimeFormat(locale, { month: "long" }).format(
    new Date(2024, d.getMonth()),
  );
  return `${d.getDate()}. ${monthName}`;
}
