import { applyCommandInterceptorOverridesToEntries } from "../../modules/overrides.js";
const GLOBAL_KEY = "__openMercatoCommandInterceptors__";
let _entries = null;
function readGlobal() {
  try {
    const value = globalThis[GLOBAL_KEY];
    return Array.isArray(value) ? value : null;
  } catch {
    return null;
  }
}
function writeGlobal(entries) {
  try {
    ;
    globalThis[GLOBAL_KEY] = entries;
  } catch {
  }
}
function registerCommandInterceptors(entries) {
  const finalEntries = applyCommandInterceptorOverridesToEntries(entries);
  const flat = [];
  for (const entry of finalEntries) {
    for (const interceptor of entry.interceptors) {
      flat.push({ moduleId: entry.moduleId, interceptor });
    }
  }
  _entries = flat;
  writeGlobal(flat);
}
function getAllCommandInterceptors() {
  const globalEntries = readGlobal();
  if (globalEntries) return globalEntries;
  if (!_entries) return [];
  return _entries;
}
function getAllCommandInterceptorInstances() {
  return getAllCommandInterceptors().map((entry) => entry.interceptor);
}
export {
  getAllCommandInterceptorInstances,
  getAllCommandInterceptors,
  registerCommandInterceptors
};
//# sourceMappingURL=command-interceptor-store.js.map
