function formatDate(date, format) {
  let we = date.getDay();
  let z = getWeek(date);
  let qut = Math.floor((date.getMonth() + 3) / 3).toString();
  const opt = {
    "Y+": date.getFullYear().toString(),
    // 年
    "m+": (date.getMonth() + 1).toString(),
    // 月(月份从0开始，要+1)
    "d+": date.getDate().toString(),
    // 日
    "H+": date.getHours().toString(),
    // 时
    "M+": date.getMinutes().toString(),
    // 分
    "S+": date.getSeconds().toString(),
    // 秒
    "q+": qut
    // 季度
  };
  const week = {
    "0": "\u65E5",
    "1": "\u4E00",
    "2": "\u4E8C",
    "3": "\u4E09",
    "4": "\u56DB",
    "5": "\u4E94",
    "6": "\u516D"
  };
  const quarter = {
    "1": "\u4E00",
    "2": "\u4E8C",
    "3": "\u4E09",
    "4": "\u56DB"
  };
  if (/(W+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length > 1 ? RegExp.$1.length > 2 ? "\u661F\u671F" + week[we] : "\u5468" + week[we] : week[we]);
  if (/(Q+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 4 ? "\u7B2C" + quarter[qut] + "\u5B63\u5EA6" : quarter[qut]);
  if (/(Z+)/.test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? "\u7B2C" + z + "\u5468" : z + "");
  for (let k in opt) {
    let r = new RegExp("(" + k + ")").exec(format);
    if (r) format = format.replace(r[1], RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, "0"));
  }
  return format;
}
function getWeek(dateTime) {
  let temptTime = new Date(dateTime.getTime());
  let weekday = temptTime.getDay() || 7;
  temptTime.setDate(temptTime.getDate() - weekday + 1 + 5);
  let firstDay = new Date(temptTime.getFullYear(), 0, 1);
  let dayOfWeek = firstDay.getDay();
  let spendDay = 1;
  if (dayOfWeek != 0) spendDay = 7 - dayOfWeek + 1;
  firstDay = new Date(temptTime.getFullYear(), 0, 1 + spendDay);
  let d = Math.ceil((temptTime.valueOf() - firstDay.valueOf()) / 864e5);
  let result = Math.ceil(d / 7);
  return result;
}
function formatPast(param, format = "YYYY-mm-dd") {
  let t, s;
  let time = (/* @__PURE__ */ new Date()).getTime();
  typeof param === "string" || "object" ? t = new Date(param).getTime() : t = param;
  time = Number.parseInt(`${time - t}`);
  if (time < 1e4) {
    return "\u521A\u521A";
  } else if (time < 6e4 && time >= 1e4) {
    s = Math.floor(time / 1e3);
    return `${s}\u79D2\u524D`;
  } else if (time < 36e5 && time >= 6e4) {
    s = Math.floor(time / 6e4);
    return `${s}\u5206\u949F\u524D`;
  } else if (time < 864e5 && time >= 36e5) {
    s = Math.floor(time / 36e5);
    return `${s}\u5C0F\u65F6\u524D`;
  } else if (time < 2592e5 && time >= 864e5) {
    s = Math.floor(time / 864e5);
    return `${s}\u5929\u524D`;
  } else {
    let date = typeof param === "string" || "object" ? new Date(param) : param;
    return formatDate(date, format);
  }
}
function formatAxis(param, t) {
  let hour = new Date(param).getHours();
  const defaultMessages = {
    dawnGreeting: "\u51CC\u6668\u597D",
    mornGreeting: "\u65E9\u4E0A\u597D",
    amGreeting: "\u4E0A\u5348\u597D",
    noonGreeting: "\u4E2D\u5348\u597D",
    pmGreeting: "\u4E0B\u5348\u597D",
    duskGreeting: "\u508D\u665A\u597D",
    eveningGreeting: "\u665A\u4E0A\u597D",
    nightGreeting: "\u591C\u91CC\u597D"
  };
  const getMessage = (key) => {
    if (t) {
      return t(`message.list.${key}`);
    }
    return defaultMessages[key];
  };
  if (hour < 6) return getMessage("dawnGreeting");
  else if (hour < 9) return getMessage("mornGreeting");
  else if (hour < 12) return getMessage("amGreeting");
  else if (hour < 14) return getMessage("noonGreeting");
  else if (hour < 17) return getMessage("pmGreeting");
  else if (hour < 19) return getMessage("duskGreeting");
  else if (hour < 22) return getMessage("eveningGreeting");
  else return getMessage("nightGreeting");
}
function getBdate(num = 1) {
  const firstDay = /* @__PURE__ */ new Date();
  firstDay.setDate(num);
  return formatDate(firstDay, "YYYY-mm-dd");
}
function getEdate(num = 0) {
  const lastDay = /* @__PURE__ */ new Date();
  lastDay.setMonth(lastDay.getMonth() + 1, 0);
  if (num > 0) lastDay.setDate(num);
  return formatDate(lastDay, "YYYY-mm-dd");
}

export { formatAxis, formatDate, formatPast, getBdate, getEdate, getWeek };
