import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
function filterPending(items, filters = {}, now = Date.now()) {
  let out = [...items];
  const { taskContains, olderThanMs, newerThanMs, sort, limit } = filters;
  if (taskContains) {
    const q = taskContains.toLowerCase();
    out = out.filter((it) => (it.task || "").toLowerCase().includes(q));
  }
  if (typeof olderThanMs === "number") {
    out = out.filter(
      (it) => typeof it.createdAt === "number" && now - it.createdAt > olderThanMs
    );
  }
  if (typeof newerThanMs === "number") {
    out = out.filter(
      (it) => typeof it.createdAt === "number" && now - it.createdAt < newerThanMs
    );
  }
  const getTs = (t) => t === null ? Infinity : t;
  if (sort === "asc")
    out.sort((a, b) => getTs(a.createdAt) - getTs(b.createdAt));
  if (sort === "desc")
    out.sort((a, b) => getTs(b.createdAt) - getTs(a.createdAt));
  if (typeof limit === "number") out = out.slice(0, limit);
  return out;
}
export {
  filterPending
};
//# sourceMappingURL=pending-utils.js.map
