import k from "./index-toDate.js";
import D from "./index-requiredArgs.js";
import m from "./index-toInteger.js";
import { getDefaultOptions as S } from "./index-defaultOptions.js";
function U(O, p, e) {
  var r, o, a, l, n, i, d, v;
  D(2, arguments);
  var s = S(), u = m((r = (o = (a = (l = e == null ? void 0 : e.weekStartsOn) !== null && l !== void 0 ? l : e == null || (n = e.locale) === null || n === void 0 || (i = n.options) === null || i === void 0 ? void 0 : i.weekStartsOn) !== null && a !== void 0 ? a : s.weekStartsOn) !== null && o !== void 0 ? o : (d = s.locale) === null || d === void 0 || (v = d.options) === null || v === void 0 ? void 0 : v.weekStartsOn) !== null && r !== void 0 ? r : 0);
  if (!(u >= 0 && u <= 6))
    throw new RangeError("weekStartsOn must be between 0 and 6 inclusively");
  var t = k(O), f = m(p), w = t.getUTCDay(), c = f % 7, _ = (c + 7) % 7, g = (_ < u ? 7 : 0) + f - w;
  return t.setUTCDate(t.getUTCDate() + g), t;
}
export {
  U as default
};
