import { formatTimeValue as d, parseTimeValue as g, createDefaultTimeValueParts as m } from "../TimePicker/helpers.js";
function u(t, e) {
  return {
    endDate: e,
    startDate: t
  };
}
function M(t) {
  const { endDate: e, startDate: n } = t;
  return !n || !e || n.getTime() !== e.getTime() ? t : u(
    n,
    new Date(e.getTime() + 1)
  );
}
function l(t, e) {
  const n = e.getYear(t), r = String(e.getMonth(t) + 1).padStart(2, "0"), a = String(e.getDate(t)).padStart(2, "0");
  return `${n}-${r}-${a}`;
}
function h(t, e) {
  return e === "end" ? t.endDate ?? t.startDate : t.startDate ?? t.endDate;
}
function B({
  currentRangePosition: t,
  defaultCalendarMonth: e,
  referenceDate: n,
  utils: r,
  value: a
}) {
  const o = h(a, t) ?? e ?? n ?? /* @__PURE__ */ new Date();
  return r.startOfMonth(o);
}
function x({
  disableFuture: t,
  disablePast: e,
  maxDate: n,
  minDate: r,
  now: a,
  utils: o
}) {
  const s = r ? o.startOfDay(r) : void 0, f = n ? o.endOfDay(n) : void 0, i = e ? o.startOfDay(a) : void 0, c = t ? o.endOfDay(a) : void 0, D = s && i ? o.isAfter(i, s) ? i : s : s ?? i;
  return {
    maxBound: f && c ? o.isBefore(c, f) ? c : f : f ?? c,
    minBound: D
  };
}
function V(t, e, n) {
  return e ? n.formatByString(t, e) : n.format(t, "monthAndYear");
}
function O(t, e, n, r) {
  const a = r.startOfMonth(e), o = r.startOfMonth(
    r.addMonths(a, n - 1)
  ), s = r.startOfMonth(t);
  return !r.isBefore(s, a) && !r.isAfter(s, o);
}
function R(t, e, n, r) {
  const a = r.startOfMonth(t);
  return O(t, e, n, r) ? r.startOfMonth(e) : r.isBefore(a, e) ? a : r.startOfMonth(r.addMonths(a, (n - 1) * -1));
}
function T(t, e, n, r) {
  return e.minBound && r.isBefore(t, r.startOfDay(e.minBound)) || e.maxBound && r.isAfter(t, r.endOfDay(e.maxBound)) ? !0 : n?.(t) ?? !1;
}
function b(t, e, n, r) {
  const { endDate: a, startDate: o } = t, s = r.startOfDay(n);
  return e === "start" || o === null || o !== null && a !== null ? {
    nextRangePosition: "end",
    nextSelectionState: "partial",
    nextValue: u(s, null)
  } : r.isBefore(s, r.startOfDay(o)) ? {
    nextRangePosition: "start",
    nextSelectionState: "finish",
    nextValue: u(s, o)
  } : {
    nextRangePosition: "start",
    nextSelectionState: "finish",
    nextValue: u(o, s)
  };
}
function p(t) {
  return t.startDate && t.endDate ? "finish" : "partial";
}
function A(t, e, n) {
  const { endDate: r, startDate: a } = e;
  return !a || !r ? !1 : n.isWithinRange(t, [n.startOfDay(a), n.endOfDay(r)]);
}
function N(t, e, n, r, a) {
  const { endDate: o, startDate: s } = e;
  return r !== "end" || !s || o || !n ? !1 : a.isWithinRange(
    t,
    a.isBefore(a.startOfDay(n), a.startOfDay(s)) ? [a.startOfDay(n), a.endOfDay(s)] : [a.startOfDay(s), a.endOfDay(n)]
  );
}
function W(t, e) {
  return t ? d(
    {
      hours24: String(t.getHours()).padStart(2, "0"),
      minutes: String(t.getMinutes()).padStart(2, "0"),
      seconds: String(t.getSeconds()).padStart(2, "0")
    },
    e,
    "seconds"
  ) : d(m(), e, "seconds");
}
function P(t, e) {
  const n = g(e, "seconds");
  if (!n)
    return t;
  const r = new Date(t);
  return r.setHours(
    Number(n.hours24),
    Number(n.minutes),
    Number(n.seconds),
    0
  ), r;
}
function Y({
  fallbackDirection: t,
  isDateDisabled: e,
  targetDate: n,
  utils: r
}) {
  if (!e(n))
    return n;
  const a = t === "forward" ? [1, -1] : [-1, 1];
  for (let o = 1; o <= 366; o += 1)
    for (const s of a) {
      const f = r.addDays(n, o * s);
      if (!e(f))
        return f;
    }
  return null;
}
function w(t, e) {
  const r = Date.UTC(t.getFullYear(), t.getMonth(), t.getDate()), a = Date.UTC(e.getFullYear(), e.getMonth(), e.getDate());
  return Math.abs(a - r) / 864e5 + 1;
}
function C(t, e, n) {
  for (const r of t) {
    const a = n.getWeekArray(r);
    for (const o of a)
      for (const s of o)
        if (!e(s))
          return s;
  }
  return null;
}
export {
  w as computeDateRangeDayCount,
  u as createDateRangeValue,
  Y as findClosestEnabledDate,
  C as findFirstEnabledVisibleDate,
  W as formatDateRangeTimeValue,
  V as formatHeaderLabel,
  l as getDateKey,
  T as isDateDisabled,
  O as isDateVisibleInWindow,
  N as isWithinPreviewRange,
  A as isWithinSelectedRange,
  P as mergeDateWithTimeValue,
  M as normalizeSameMomentDateTimeRangeValue,
  B as resolveInitialVisibleMonth,
  x as resolveNavigationBounds,
  p as resolveRangeSelectionState,
  h as resolveSelectedRangeDate,
  R as resolveVisibleMonthForDate,
  b as selectRangeDate
};
