"use strict";
var common_vendor = require("../common/vendor.js");
var stores_modules_rateLimit = require("../stores/modules/rateLimit.js");
const getRateLimitStore = async () => {
  return stores_modules_rateLimit.useRateLimitStore();
};
const sleep = async (time) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};
const formatDate = (date) => {
  const d = new Date(date);
  const year = d.getFullYear();
  const month = String(d.getMonth() + 1).padStart(2, "0");
  const day = String(d.getDate()).padStart(2, "0");
  const hour = String(d.getHours()).padStart(2, "0");
  const minute = String(d.getMinutes()).padStart(2, "0");
  const second = String(d.getSeconds()).padStart(2, "0");
  return `${year}/${month}/${day} ${hour}:${minute}:${second}`;
};
const goTo = (url) => {
  common_vendor.index.navigateTo({
    url
  });
};
const rateLimit = async (time, n, func) => {
  const {
    timestamps
  } = common_vendor.storeToRefs(await getRateLimitStore());
  return function(...args) {
    const now = Date.now();
    while (timestamps.value.length > 0 && timestamps.value[0] <= now - time) {
      timestamps.value.shift();
    }
    if (timestamps.value.length >= n) {
      return false;
    }
    timestamps.value.push(now);
    console.log(timestamps.value);
    func == null ? void 0 : func.apply(this, args);
    return true;
  };
};
exports.formatDate = formatDate;
exports.goTo = goTo;
exports.rateLimit = rateLimit;
exports.sleep = sleep;
