"use strict";
var constant = require("dayjs/esm/constant");
var weekOfYear = (o, c, d) => {
  const proto = c.prototype;
  proto.week = function(week = null) {
    if (week !== null) {
      return this.add((week - this.week()) * 7, constant.D);
    }
    const yearStart = this.$locale().yearStart || 1;
    const noAcrossYear = this.$locale().noAcrossYear || false;
    const weekStart = this.$locale().weekStart || 1;
    console.log("\u81EA\u5B9A\u4E49week", yearStart, noAcrossYear, weekStart);
    if (this.month() === 11 && this.date() > 25) {
      const nextYearStartDay = d(this).startOf(constant.Y).add(1, constant.Y).date(yearStart);
      const thisEndOfWeek = d(this).endOf(constant.W);
      if (!noAcrossYear && nextYearStartDay.isBefore(thisEndOfWeek)) {
        return 1;
      }
      if (noAcrossYear && nextYearStartDay.isBefore(thisEndOfWeek)) {
        return d(this).startOf("week").subtract(1, constant.D).week() + 1;
      }
    }
    const yearStartDay = d(this).startOf(constant.Y).date(yearStart);
    const yearStartWeek = yearStartDay.startOf(constant.W).subtract(1, constant.MS);
    const diffInWeek = this.diff(yearStartWeek, constant.W, true);
    if (diffInWeek < 0 && yearStart !== 1 && noAcrossYear) {
      return 0;
    }
    if (diffInWeek < 0) {
      return d(this).startOf("week").week();
    }
    return Math.ceil(diffInWeek);
  };
  proto.weeks = function(week = null) {
    return this.week(week);
  };
};
module.exports = weekOfYear;
