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