"use client";
import { defaultDateLib as D } from "../classes/DateLib.js";
function w(f, g, n = 0, r = 0, l = !1, u = D) {
  const { from: o, to: i } = g || {}, { isSameDay: s, isAfter: c, isBefore: m } = u;
  let e;
  if (!o && !i)
    e = { from: f, to: n > 0 ? void 0 : f };
  else if (o && !i)
    s(o, f) ? n === 0 ? e = { from: o, to: f } : l ? e = { from: o, to: void 0 } : e = void 0 : m(f, o) ? e = { from: f, to: o } : e = { from: o, to: f };
  else if (o && i)
    if (s(o, f) && s(i, f))
      l ? e = { from: o, to: i } : e = void 0;
    else if (s(o, f))
      e = { from: o, to: n > 0 ? void 0 : f };
    else if (s(i, f))
      e = { from: f, to: n > 0 ? void 0 : f };
    else if (m(f, o))
      e = { from: f, to: i };
    else if (c(f, o))
      e = { from: o, to: f };
    else if (c(f, i))
      e = { from: o, to: f };
    else
      throw new Error("Invalid range");
  if (e?.from && e?.to) {
    const t = u.differenceInCalendarDays(e.to, e.from);
    r > 0 && t > r ? e = { from: f, to: void 0 } : n > 1 && t < n && (e = { from: f, to: void 0 });
  }
  return e;
}
export {
  w as addToRange
};
