"use client";
import { TZDate as h } from "../../../../@date-fns/tz/date/index.js";
import "../../../../@date-fns/tz/date/mini.js";
import { enUS as a } from "../../../../date-fns/locale/en-US.js";
import { endOfBroadcastWeek as f } from "../helpers/endOfBroadcastWeek.js";
import { startOfBroadcastWeek as d } from "../helpers/startOfBroadcastWeek.js";
import { addDays as m } from "../../../../date-fns/addDays.js";
import { addMonths as v } from "../../../../date-fns/addMonths.js";
import { addWeeks as p } from "../../../../date-fns/addWeeks.js";
import { addYears as O } from "../../../../date-fns/addYears.js";
import { differenceInCalendarDays as u } from "../../../../date-fns/differenceInCalendarDays.js";
import { differenceInCalendarMonths as c } from "../../../../date-fns/differenceInCalendarMonths.js";
import { eachMonthOfInterval as l } from "../../../../date-fns/eachMonthOfInterval.js";
import { endOfISOWeek as M } from "../../../../date-fns/endOfISOWeek.js";
import { endOfMonth as k } from "../../../../date-fns/endOfMonth.js";
import { endOfWeek as W } from "../../../../date-fns/endOfWeek.js";
import { endOfYear as D } from "../../../../date-fns/endOfYear.js";
import { formatDate as S } from "../../../../date-fns/format.js";
import { getISOWeek as g } from "../../../../date-fns/getISOWeek.js";
import { getMonth as y } from "../../../../date-fns/getMonth.js";
import { getYear as Y } from "../../../../date-fns/getYear.js";
import { getWeek as I } from "../../../../date-fns/getWeek.js";
import { isAfter as B } from "../../../../date-fns/isAfter.js";
import { isBefore as w } from "../../../../date-fns/isBefore.js";
import { isDate as L } from "../../../../date-fns/isDate.js";
import { isSameDay as C } from "../../../../date-fns/isSameDay.js";
import { isSameMonth as Z } from "../../../../date-fns/isSameMonth.js";
import { isSameYear as b } from "../../../../date-fns/isSameYear.js";
import { max as z } from "../../../../date-fns/max.js";
import { min as F } from "../../../../date-fns/min.js";
import { setMonth as A } from "../../../../date-fns/setMonth.js";
import { setYear as N } from "../../../../date-fns/setYear.js";
import { startOfDay as _ } from "../../../../date-fns/startOfDay.js";
import { startOfISOWeek as j } from "../../../../date-fns/startOfISOWeek.js";
import { startOfMonth as x } from "../../../../date-fns/startOfMonth.js";
import { startOfWeek as H } from "../../../../date-fns/startOfWeek.js";
import { startOfYear as K } from "../../../../date-fns/startOfYear.js";
class o {
  /**
   * Creates an instance of `DateLib`.
   *
   * @param options Configuration options for the date library.
   * @param overrides Custom overrides for the date library functions.
   */
  constructor(t, i) {
    this.Date = Date, this.today = () => this.overrides?.today ? this.overrides.today() : this.options.timeZone ? h.tz(this.options.timeZone) : new this.Date(), this.newDate = (r, e, s) => this.overrides?.newDate ? this.overrides.newDate(r, e, s) : this.options.timeZone ? new h(r, e, s, this.options.timeZone) : new Date(r, e, s), this.addDays = (r, e) => this.overrides?.addDays ? this.overrides.addDays(r, e) : m(r, e), this.addMonths = (r, e) => this.overrides?.addMonths ? this.overrides.addMonths(r, e) : v(r, e), this.addWeeks = (r, e) => this.overrides?.addWeeks ? this.overrides.addWeeks(r, e) : p(r, e), this.addYears = (r, e) => this.overrides?.addYears ? this.overrides.addYears(r, e) : O(r, e), this.differenceInCalendarDays = (r, e) => this.overrides?.differenceInCalendarDays ? this.overrides.differenceInCalendarDays(r, e) : u(r, e), this.differenceInCalendarMonths = (r, e) => this.overrides?.differenceInCalendarMonths ? this.overrides.differenceInCalendarMonths(r, e) : c(r, e), this.eachMonthOfInterval = (r) => this.overrides?.eachMonthOfInterval ? this.overrides.eachMonthOfInterval(r) : l(r), this.endOfBroadcastWeek = (r) => this.overrides?.endOfBroadcastWeek ? this.overrides.endOfBroadcastWeek(r) : f(r, this), this.endOfISOWeek = (r) => this.overrides?.endOfISOWeek ? this.overrides.endOfISOWeek(r) : M(r), this.endOfMonth = (r) => this.overrides?.endOfMonth ? this.overrides.endOfMonth(r) : k(r), this.endOfWeek = (r, e) => this.overrides?.endOfWeek ? this.overrides.endOfWeek(r, e) : W(r, this.options), this.endOfYear = (r) => this.overrides?.endOfYear ? this.overrides.endOfYear(r) : D(r), this.format = (r, e, s) => {
      const n = this.overrides?.format ? this.overrides.format(r, e, this.options) : S(r, e, this.options);
      return this.options.numerals && this.options.numerals !== "latn" ? this.replaceDigits(n) : n;
    }, this.getISOWeek = (r) => this.overrides?.getISOWeek ? this.overrides.getISOWeek(r) : g(r), this.getMonth = (r, e) => this.overrides?.getMonth ? this.overrides.getMonth(r, this.options) : y(r, this.options), this.getYear = (r, e) => this.overrides?.getYear ? this.overrides.getYear(r, this.options) : Y(r, this.options), this.getWeek = (r, e) => this.overrides?.getWeek ? this.overrides.getWeek(r, this.options) : I(r, this.options), this.isAfter = (r, e) => this.overrides?.isAfter ? this.overrides.isAfter(r, e) : B(r, e), this.isBefore = (r, e) => this.overrides?.isBefore ? this.overrides.isBefore(r, e) : w(r, e), this.isDate = (r) => this.overrides?.isDate ? this.overrides.isDate(r) : L(r), this.isSameDay = (r, e) => this.overrides?.isSameDay ? this.overrides.isSameDay(r, e) : C(r, e), this.isSameMonth = (r, e) => this.overrides?.isSameMonth ? this.overrides.isSameMonth(r, e) : Z(r, e), this.isSameYear = (r, e) => this.overrides?.isSameYear ? this.overrides.isSameYear(r, e) : b(r, e), this.max = (r) => this.overrides?.max ? this.overrides.max(r) : z(r), this.min = (r) => this.overrides?.min ? this.overrides.min(r) : F(r), this.setMonth = (r, e) => this.overrides?.setMonth ? this.overrides.setMonth(r, e) : A(r, e), this.setYear = (r, e) => this.overrides?.setYear ? this.overrides.setYear(r, e) : N(r, e), this.startOfBroadcastWeek = (r, e) => this.overrides?.startOfBroadcastWeek ? this.overrides.startOfBroadcastWeek(r, this) : d(r, this), this.startOfDay = (r) => this.overrides?.startOfDay ? this.overrides.startOfDay(r) : _(r), this.startOfISOWeek = (r) => this.overrides?.startOfISOWeek ? this.overrides.startOfISOWeek(r) : j(r), this.startOfMonth = (r) => this.overrides?.startOfMonth ? this.overrides.startOfMonth(r) : x(r), this.startOfWeek = (r, e) => this.overrides?.startOfWeek ? this.overrides.startOfWeek(r, this.options) : H(r, this.options), this.startOfYear = (r) => this.overrides?.startOfYear ? this.overrides.startOfYear(r) : K(r), this.options = { locale: a, ...t }, this.overrides = i;
  }
  /**
   * Generates a mapping of Arabic digits (0-9) to the target numbering system
   * digits.
   *
   * @since 9.5.0
   * @returns A record mapping Arabic digits to the target numerals.
   */
  getDigitMap() {
    const { numerals: t = "latn" } = this.options, i = new Intl.NumberFormat("en-US", {
      numberingSystem: t
    }), r = {};
    for (let e = 0; e < 10; e++)
      r[e.toString()] = i.format(e);
    return r;
  }
  /**
   * Replaces Arabic digits in a string with the target numbering system digits.
   *
   * @since 9.5.0
   * @param input The string containing Arabic digits.
   * @returns The string with digits replaced.
   */
  replaceDigits(t) {
    const i = this.getDigitMap();
    return t.replace(/\d/g, (r) => i[r] || r);
  }
  /**
   * Formats a number using the configured numbering system.
   *
   * @since 9.5.0
   * @param value The number to format.
   * @returns The formatted number as a string.
   */
  formatNumber(t) {
    return this.replaceDigits(t.toString());
  }
  /**
   * Returns the preferred ordering for month and year labels for the current
   * locale.
   */
  getMonthYearOrder() {
    const t = this.options.locale?.code;
    return t && o.yearFirstLocales.has(t) ? "year-first" : "month-first";
  }
  /**
   * Formats the month/year pair respecting locale conventions.
   *
   * @since 9.11.0
   */
  formatMonthYear(t) {
    const { locale: i, timeZone: r, numerals: e } = this.options, s = i?.code;
    if (s && o.yearFirstLocales.has(s))
      try {
        return new Intl.DateTimeFormat(s, {
          month: "long",
          year: "numeric",
          timeZone: r,
          numberingSystem: e
        }).format(t);
      } catch {
      }
    const n = this.getMonthYearOrder() === "year-first" ? "y LLLL" : "LLLL y";
    return this.format(t, n);
  }
}
o.yearFirstLocales = /* @__PURE__ */ new Set([
  "eu",
  "hu",
  "ja",
  "ja-Hira",
  "ja-JP",
  "ko",
  "ko-KR",
  "lt",
  "lt-LT",
  "lv",
  "lv-LV",
  "mn",
  "mn-MN",
  "zh",
  "zh-CN",
  "zh-HK",
  "zh-TW"
]);
const Ir = new o();
export {
  o as DateLib,
  Ir as defaultDateLib,
  a as defaultLocale
};
