import { format as formatDateFns } from "date-fns/format";
const DAY_FIRST_LOCALE_CODES = /* @__PURE__ */ new Set([
  "pl",
  "de",
  "fr",
  "es",
  "it",
  "pt",
  "nl",
  "ru",
  "cs",
  "sk",
  "hu",
  "ro"
]);
const SYSTEM_FORMAT_VALUES = /* @__PURE__ */ new Set(["auto", "default", "locale", "system"]);
function getLocaleCode(locale) {
  if (!locale) return "";
  if (typeof locale === "string") return locale.split("-")[0]?.toLowerCase() ?? "";
  return locale.code?.split("-")[0]?.toLowerCase() ?? "";
}
function normalizeDateFormatPattern(value) {
  const trimmed = value?.trim();
  if (!trimmed) return null;
  if (SYSTEM_FORMAT_VALUES.has(trimmed.toLowerCase())) return null;
  return trimmed.replace(/YYYY/g, "yyyy").replace(/YY/g, "yy").replace(/DD/g, "dd");
}
function deriveDateDisplayFormat(locale) {
  const code = getLocaleCode(locale);
  return code && DAY_FIRST_LOCALE_CODES.has(code) ? "d MMM yyyy" : "MMM d, yyyy";
}
function resolvePublicDateFormat(locale, explicitFormat) {
  return normalizeDateFormatPattern(explicitFormat) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_OM_DATE_FORMAT) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_DATE_FORMAT) ?? deriveDateDisplayFormat(locale);
}
function resolvePublicDateTimeFormat(locale, explicitFormat) {
  const dateFormat = deriveDateDisplayFormat(locale);
  return normalizeDateFormatPattern(explicitFormat) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_OM_DATE_TIME_FORMAT) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_DATE_TIME_FORMAT) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_OM_DATE_FORMAT) ?? normalizeDateFormatPattern(process.env.NEXT_PUBLIC_DATE_FORMAT) ?? `${dateFormat} HH:mm`;
}
function formatWithPublicDateFormat(date, format, locale) {
  try {
    return formatDateFns(date, format, locale ? { locale } : void 0);
  } catch {
    return null;
  }
}
export {
  deriveDateDisplayFormat,
  formatWithPublicDateFormat,
  normalizeDateFormatPattern,
  resolvePublicDateFormat,
  resolvePublicDateTimeFormat
};
//# sourceMappingURL=date-format.js.map
