import { startOfWeek as y, getDay as D, addMonths as w, startOfMonth as M, addDays as f, getDate as h, endOfMonth as g, subMonths as k, getMonth as O, isEqual as W } from "date-fns";
import { WEEK_START as x } from "./datepicker-constants.js";
const u = (t) => t ? new Date(t) : /* @__PURE__ */ new Date(), S = (t, e, n) => {
  const s = u(JSON.parse(JSON.stringify(t))), a = [];
  for (let o = 0; o < 7; o++) {
    const r = f(s, o), c = O(r) !== e;
    a.push({
      text: r.getDate(),
      value: r,
      currentMonth: !c,
      isFirstDayOfMonth: r.getDate() === 1 && !c,
      // will be selected if the date is the same as the selected day and is from the current month
      selected: n ? r.getDate() === n && !c : !1
    });
  }
  return a;
}, p = (t, e) => !t || !e ? !1 : W(t, e), N = (t, e, n) => {
  const s = [], a = u(new Date(e, t)), o = u(new Date(e, t + 1, 0)), c = y(a, { weekStartsOn: x }), i = (d) => {
    const m = S(d, t, n);
    if (s.push({ days: m }), !s[s.length - 1].days.some(
      (l) => p(l.value, o)
    )) {
      const l = f(d, 7);
      i(l);
    }
  };
  return i(c), s;
}, v = (t, e) => {
  const n = [1, 2, 3, 4, 5, 6, 7].map((o) => new Intl.DateTimeFormat(t, { weekday: "short", timeZone: "UTC" }).format(/* @__PURE__ */ new Date(`2017-01-0${o}T00:00:00+00:00`)).slice(0, 2)), s = n.slice(0, e), a = n.slice(e + 1, n.length);
  return [n[e]].concat(...a).concat(...s);
}, E = (t, e, n) => new Intl.DateTimeFormat(n, { month: e }).format(new Date(2e3, t, 1)), I = (t, e, n) => new Intl.DateTimeFormat(n, { dateStyle: e }).format(new Date(t)), P = (t) => {
  const e = new Date(t), n = D(e), s = w(e, 1), a = M(s), o = D(a), r = (n - o + 7) % 7, c = f(a, r);
  return h(c);
}, b = (t) => {
  const e = new Date(t), n = D(e);
  let a = g(k(e, 1));
  for (; D(a) !== n; )
    a = f(a, -1);
  return h(a);
};
export {
  P as calculateNextFocusDate,
  b as calculatePrevFocusDate,
  I as formatDate,
  E as formatMonth,
  N as getCalendarDays,
  v as getWeekDayNames
};
//# sourceMappingURL=utils.js.map
