const registeredMethodsByPath = /* @__PURE__ */ new Map();
function normalizePath(path) {
  if (typeof path !== "string") return null;
  const trimmed = path.trim();
  if (!trimmed || !trimmed.startsWith("/")) return null;
  return (trimmed.length > 1 ? trimmed.replace(/\/+$/, "") : trimmed).toLowerCase() || "/";
}
function normalizeMethods(methods) {
  if (!Array.isArray(methods)) return [];
  const normalized = methods.filter((method) => typeof method === "string" && method.trim().length > 0).map((method) => method.trim().toUpperCase());
  return Array.from(new Set(normalized)).sort((first, second) => first < second ? -1 : first > second ? 1 : 0);
}
function registerMfaPendingAccessRoutes(routes) {
  for (const route of Array.isArray(routes) ? routes : []) {
    const path = normalizePath(route?.path ?? "");
    const methods = normalizeMethods(route?.methods);
    if (!path || !methods.length) continue;
    const existing = registeredMethodsByPath.get(path);
    if (!existing) {
      registeredMethodsByPath.set(path, new Set(methods));
      continue;
    }
    for (const method of methods) existing.add(method);
  }
}
function isMfaPendingAccessAllowed(method, pathname) {
  const path = normalizePath(typeof pathname === "string" ? pathname : "");
  if (!path) return false;
  if (typeof method !== "string" || method.trim().length === 0) return false;
  const methods = registeredMethodsByPath.get(path);
  if (!methods) return false;
  return methods.has(method.trim().toUpperCase());
}
function listMfaPendingAccessRoutes() {
  return Array.from(registeredMethodsByPath.entries()).map(([path, methods]) => ({ path, methods: Array.from(methods).sort((first, second) => first < second ? -1 : first > second ? 1 : 0) })).sort((first, second) => first.path < second.path ? -1 : first.path > second.path ? 1 : 0);
}
export {
  isMfaPendingAccessAllowed,
  listMfaPendingAccessRoutes,
  registerMfaPendingAccessRoutes
};
//# sourceMappingURL=mfaPendingAccess.js.map
