import { format } from "date-fns";
import { ar, enUS } from "date-fns/locale";

import type { Language } from "@/lib/i18n/config";

/**
 * Date formatting for the provider screens.
 *
 * Uses date-fns locales rather than `Intl` with `ar-SA` — that locale defaults
 * to the Hijri calendar, which is not what these Gregorian timestamps mean.
 * Same decision (and reason) as the calendar module.
 */
function localeFor(language: Language) {
  return language === "ar" ? ar : enUS;
}

/** e.g. "12 Mar 2026" */
export function formatDay(iso: string, language: Language): string {
  return format(new Date(iso), "d MMM yyyy", { locale: localeFor(language) });
}

/** e.g. "12 Mar 2026, 14:30" */
export function formatDateTime(iso: string, language: Language): string {
  return format(new Date(iso), "d MMM yyyy, HH:mm", {
    locale: localeFor(language),
  });
}
