import {
  require_dayjs_min
} from "./chunk-KSAUAMBE.js";
import {
  __commonJS,
  __toESM
} from "./chunk-V4OQ3NZ2.js";

// node_modules/dayjs/locale/fa.js
var require_fa = __commonJS({
  "node_modules/dayjs/locale/fa.js"(exports, module) {
    !(function(_, e) {
      "object" == typeof exports && "undefined" != typeof module ? module.exports = e(require_dayjs_min()) : "function" == typeof define && define.amd ? define(["dayjs"], e) : (_ = "undefined" != typeof globalThis ? globalThis : _ || self).dayjs_locale_fa = e(_.dayjs);
    })(exports, (function(_) {
      "use strict";
      function e(_2) {
        return _2 && "object" == typeof _2 && "default" in _2 ? _2 : { default: _2 };
      }
      var t = e(_), d = { name: "fa", weekdays: "یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"), weekdaysShort: "یک‌شنبه_دوشنبه_سه‌شنبه_چهارشنبه_پنج‌شنبه_جمعه_شنبه".split("_"), weekdaysMin: "ی_د_س_چ_پ_ج_ش".split("_"), weekStart: 6, months: "ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"), monthsShort: "ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"), ordinal: function(_2) {
        return _2;
      }, formats: { LT: "HH:mm", LTS: "HH:mm:ss", L: "DD/MM/YYYY", LL: "D MMMM YYYY", LLL: "D MMMM YYYY HH:mm", LLLL: "dddd, D MMMM YYYY HH:mm" }, relativeTime: { future: "در %s", past: "%s پیش", s: "چند ثانیه", m: "یک دقیقه", mm: "%d دقیقه", h: "یک ساعت", hh: "%d ساعت", d: "یک روز", dd: "%d روز", M: "یک ماه", MM: "%d ماه", y: "یک سال", yy: "%d سال" } };
      return t.default.locale(d, null, true), d;
    }));
  }
});

// node_modules/jalaliday/dist/_chunks/plugin-CKyDwoA_.mjs
var import_fa = __toESM(require_fa(), 1);
function g2d(gy, gm, gd) {
  let d = div((gy + div(gm - 8, 6) + 100100) * 1461, 4) + div(153 * mod(gm + 9, 12) + 2, 5) + gd - 34840408;
  d = d - div(div(gy + 100100 + div(gm - 8, 6), 100) * 3, 4) + 752;
  return d;
}
var breaks = [
  -61,
  9,
  38,
  199,
  426,
  686,
  756,
  818,
  1111,
  1181,
  1210,
  1635,
  2060,
  2097,
  2192,
  2262,
  2324,
  2394,
  2456,
  3178
];
var _floor = Math.floor;
function mod(a, b) {
  return a - ~~(a / b) * b;
}
function div(a, b) {
  return ~~(a / b);
}
function jalCal(jy, withoutLeap) {
  const bl = breaks.length;
  const gy = jy + 621;
  let leapJ = -14;
  let jp = breaks[0];
  let jm;
  let jump;
  let leap;
  let n;
  if (jy < jp || jy >= breaks[bl - 1]) throw new Error(`Invalid Jalaali year ${jy}`);
  for (let i = 1; i < bl; i += 1) {
    jm = breaks[i];
    jump = jm - jp;
    if (jy < jm) break;
    leapJ = leapJ + div(jump, 33) * 8 + div(mod(jump, 33), 4);
    jp = jm;
  }
  n = jy - jp;
  leapJ = leapJ + div(n, 33) * 8 + div(mod(n, 33) + 3, 4);
  if (mod(jump, 33) === 4 && jump - n === 4) leapJ += 1;
  const leapG = div(gy, 4) - div((div(gy, 100) + 1) * 3, 4) - 150;
  const march = 20 + leapJ - leapG;
  if (withoutLeap) return {
    gy,
    march
  };
  if (jump - n < 6) n = n - jump + div(jump + 4, 33) * 33;
  leap = mod(mod(n + 1, 33) - 1, 4);
  if (leap === -1) leap = 4;
  return {
    leap,
    gy,
    march
  };
}
function j2d(jy, jm, jd) {
  const r = jalCal(jy, true);
  return g2d(r.gy, 3, r.march) + (jm - 1) * 31 - div(jm, 7) * (jm - 7) + jd - 1;
}
function d2g(jdn) {
  let j = 4 * jdn + 139361631;
  j = j + div(div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908;
  const i = div(mod(j, 1461), 4) * 5 + 308;
  const gd = div(mod(i, 153), 5) + 1;
  const gm = mod(div(i, 153), 12) + 1;
  const gy = div(j, 1461) - 100100 + div(8 - gm, 6);
  return [
    gy,
    gm,
    gd
  ];
}
function toGregorian(jy, jm, jd) {
  return d2g(j2d(jy, jm, jd));
}
function toJalaali(year, month, day) {
  const result = {
    year,
    month,
    day
  };
  const array = [
    0,
    31,
    59,
    90,
    120,
    151,
    181,
    212,
    243,
    273,
    304,
    334
  ];
  let days;
  if (year <= 1600) {
    year -= 621;
    result.year = 0;
  } else {
    year -= 1600;
    result.year = 979;
  }
  const temp = year > 2 ? year + 1 : year;
  days = _floor((temp + 3) / 4) + 365 * year - _floor((temp + 99) / 100) - 80 + array[month - 1] + _floor((temp + 399) / 400) + day;
  result.year += 33 * _floor(days / 12053);
  days %= 12053;
  result.year += 4 * _floor(days / 1461);
  days %= 1461;
  if (days > 365) {
    result.year += _floor((days - 1) / 365);
    days = (days - 1) % 365;
  }
  result.month = days < 186 ? 1 + _floor(days / 31) : 7 + _floor((days - 186) / 30);
  result.day = 1 + (days < 186 ? days % 31 : (days - 186) % 30);
  return [
    result.year,
    result.month,
    result.day
  ];
}
var calendar_default = {
  J: (y, m, d) => toJalaali(y, m, d),
  G: (y, m, d) => toGregorian(y, m, d)
};
var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})[-/]?(\d{0,2})(.*)$/;
var REGEX_FORMAT = /\[.*?\]|jY{2,4}|jM{1,4}|jD{1,2}|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;
var DATE = "date";
var D = "day";
var M = "month";
var Y = "year";
var W = "week";
var FORMAT_DEFAULT = "YYYY-MM-DDTHH:mm:ssZ";
var fa$1 = { jmonths: "فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند".split("_") };
var plugin = (o, Dayjs, dayjs) => {
  const proto = Dayjs.prototype;
  const U = proto.$utils();
  const $isJalali = (v) => v.$C === "jalali";
  const $prettyUnit = U.prettyUnit || U.p;
  const $isUndefined = U.isUndefined || U.u;
  const $padStart = U.padStart || U.s;
  const $monthDiff = U.monthDiff || U.m;
  const $absFloor = U.absFloor || U.a;
  const wrapperOfTruth = (action) => function(...args) {
    const unsure = action.bind(this)(...args);
    unsure.$C = this.$C;
    if (unsure.isJalali()) unsure.InitJalali();
    return unsure;
  };
  proto.startOf = wrapperOfTruth(proto.startOf);
  proto.endOf = wrapperOfTruth(proto.endOf);
  proto.add = wrapperOfTruth(proto.add);
  proto.subtract = wrapperOfTruth(proto.subtract);
  proto.set = wrapperOfTruth(proto.set);
  const oldParse = proto.parse;
  const oldInit = proto.init;
  const oldStartOf = proto.startOf;
  const old$Set = proto.$set;
  const oldAdd = proto.add;
  const oldFormat = proto.format;
  const oldDiff = proto.diff;
  const oldYear = proto.year;
  const oldMonth = proto.month;
  const oldDate = proto.date;
  const oldDaysInMonth = proto.daysInMonth;
  const oldToArray = proto.toArray;
  dayjs.$C = "gregory";
  dayjs.$fdow = 6;
  dayjs.calendar = function(calendar) {
    dayjs.$C = calendar;
    return dayjs;
  };
  proto.calendar = function(calendar) {
    const that = this.clone();
    that.$C = calendar;
    if (that.isJalali()) that.InitJalali();
    return that;
  };
  proto.isJalali = function() {
    return $isJalali(this);
  };
  dayjs.en.jmonths = "Farvardin_Ordibehesht_Khordaad_Tir_Mordaad_Shahrivar_Mehr_Aabaan_Aazar_Dey_Bahman_Esfand".split("_");
  dayjs.locale("fa", {
    ...import_fa.default,
    ...fa$1
  }, true);
  const wrapper = function(date, instance) {
    return dayjs(date, {
      locale: instance.$L,
      utc: instance.$u,
      calendar: instance.$C
    });
  };
  proto.init = function(cfg = {}) {
    oldInit.bind(this)(cfg);
    if (this.isJalali()) this.InitJalali();
  };
  proto.parse = function(cfg) {
    this.$C = cfg.calendar || this.$C || dayjs.$C;
    if (cfg.jalali && typeof cfg.date === "string" && /.*[^Z]$/i.test(cfg.date)) {
      const reg = cfg.date.match(REGEX_PARSE);
      if (reg) {
        const [y, m, d] = calendar_default.G(Number.parseInt(reg[1], 10), Number.parseInt(reg[2], 10), Number.parseInt(reg[3] || 1, 10));
        cfg.date = `${y}-${m}-${d}${reg[4] || ""}`;
      }
    }
    return oldParse.bind(this)(cfg);
  };
  proto.InitJalali = function() {
    const [jy, jm, jd] = calendar_default.J(this.$y, this.$M + 1, this.$D);
    this.$jy = jy;
    this.$jM = jm - 1;
    this.$jD = jd;
  };
  proto.startOf = function(units, startOf) {
    if (!$isJalali(this)) return oldStartOf.bind(this)(units, startOf);
    const isStartOf = !$isUndefined(startOf) ? startOf : true;
    const unit = $prettyUnit(units);
    const instanceFactory = (d, m, y = this.$jy) => {
      const [gy, gm, gd] = calendar_default.G(y, m + 1, d);
      const ins = wrapper(new Date(gy, gm - 1, gd), this);
      return (isStartOf ? ins : ins.endOf(D)).$set("hour", 1);
    };
    const WModifier = (this.$W + (7 - dayjs.$fdow)) % 7;
    switch (unit) {
      case Y:
        return isStartOf ? instanceFactory(1, 0) : instanceFactory(0, 0, this.$jy + 1);
      case M:
        return isStartOf ? instanceFactory(1, this.$jM) : instanceFactory(0, (this.$jM + 1) % 12, this.$jy + Math.floor((this.$jM + 1) / 12));
      case W:
        return isStartOf ? instanceFactory(this.$jD - WModifier, this.$jM) : instanceFactory(this.$jD + (6 - WModifier), this.$jM);
      default:
        return oldStartOf.bind(this)(units, startOf);
    }
  };
  proto.$set = function(units, int) {
    if (!$isJalali(this)) return old$Set.bind(this)(units, int);
    const unit = $prettyUnit(units);
    const instanceFactory = (d, m, y = this.$jy) => {
      const [gy, gm, gd] = calendar_default.G(y, m + 1, d);
      this.$d.setFullYear(gy);
      this.$d.setMonth(gm - 1);
      this.$d.setDate(gd);
      return this;
    };
    switch (unit) {
      case DATE:
      case D:
        instanceFactory(int, this.$jM);
        break;
      case M:
        instanceFactory(this.$jD, int);
        break;
      case Y:
        instanceFactory(this.$jD, this.$jM, int);
        break;
      default:
        return old$Set.bind(this)(units, int);
    }
    this.init();
    return this;
  };
  proto.add = function(number, units) {
    if (!$isJalali(this)) return oldAdd.bind(this)(number, units);
    number = Number(number);
    const unit = units && (units.length === 1 || units === "ms") ? units : $prettyUnit(units);
    const instanceFactory = (u, n) => {
      const date = this.set(DATE, 1).set(u, n + number);
      return date.set(DATE, Math.min(this.$jD, date.daysInMonth()));
    };
    if (["M", M].includes(unit)) {
      const n = this.$jM + number;
      const y = n < 0 ? -Math.ceil(-n / 12) : Math.floor(n / 12);
      const d = this.$jD;
      const x = this.set(D, 1).add(y, Y).set(M, n - y * 12);
      return x.set(D, Math.min(x.daysInMonth(), d));
    }
    if (["y", Y].includes(unit)) return instanceFactory(Y, this.$jy);
    if (["d", D].includes(unit)) {
      const date = new Date(this.$d);
      date.setDate(date.getDate() + number);
      return wrapper(date, this);
    }
    if (["w", W].includes(unit)) {
      const date = new Date(this.$d);
      date.setDate(date.getDate() + number * 7);
      return wrapper(date, this);
    }
    return oldAdd.bind(this)(number, units);
  };
  proto.format = function(formatStr, localeObject) {
    if (!$isJalali(this)) return oldFormat.bind(this)(formatStr, localeObject);
    const str = formatStr || FORMAT_DEFAULT;
    const locale = localeObject || this.$locale();
    const { jmonths } = locale;
    return str.replace(REGEX_FORMAT, (match) => {
      if (match.includes("[")) return match.replace(/\[|\]/g, "");
      switch (match) {
        case "YY":
          return String(this.$jy).slice(-2);
        case "YYYY":
          return String(this.$jy);
        case "M":
          return String(this.$jM + 1);
        case "MM":
          return $padStart(this.$jM + 1, 2, "0");
        case "MMM":
          return jmonths[this.$jM].slice(0, 3);
        case "MMMM":
          return jmonths[this.$jM];
        case "D":
          return String(this.$jD);
        case "DD":
          return $padStart(this.$jD, 2, "0");
        default:
          return oldFormat.bind(this)(match, localeObject);
      }
    });
  };
  proto.diff = function(input, units, float) {
    if (!$isJalali(this)) return oldDiff.bind(this)(input, units, float);
    const unit = $prettyUnit(units);
    const that = dayjs(input);
    let result = $monthDiff(this, that);
    switch (unit) {
      case Y:
        result /= 12;
        break;
      case M:
        break;
      default:
        return oldDiff.bind(this)(input, units, float);
    }
    return float ? result : $absFloor(result);
  };
  proto.$g = function(input, get, set) {
    if ($isUndefined(input)) return this[get];
    return this.set(set, input);
  };
  proto.year = function(input) {
    if (!$isJalali(this)) return oldYear.bind(this)(input);
    return this.$g(input, "$jy", Y);
  };
  proto.month = function(input) {
    if (!$isJalali(this)) return oldMonth.bind(this)(input);
    return this.$g(input, "$jM", M);
  };
  proto.date = function(input) {
    if (!$isJalali(this)) return oldDate.bind(this)(input);
    return this.$g(input, "$jD", D);
  };
  proto.daysInMonth = function() {
    if (!$isJalali(this)) return oldDaysInMonth.bind(this)();
    return this.endOf(M).$jD;
  };
  if (oldToArray) proto.toArray = function() {
    if (!$isJalali(this)) return oldToArray.bind(this)();
    return [
      this.$jy,
      this.$jM,
      this.$jD,
      this.$H,
      this.$m,
      this.$s,
      this.$ms
    ];
  };
  proto.clone = function() {
    return wrapper(this.toDate(), this);
  };
};
var plugin_default = plugin;
export {
  plugin_default as default
};
//# sourceMappingURL=jalaliday_dayjs.js.map
