import { compose } from "redux";
const middlewareDispatchFns = /* @__PURE__ */ new Map();
let store;
const queryMiddleware = (_store) => {
  store = _store;
  return (next) => (action) => (
    // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
    compose(...middlewareDispatchFns.values())(next)(action)
  );
};
const addMiddleware = ({
  reducerPath,
  middleware
}) => {
  if (middlewareDispatchFns.has(reducerPath) || !store) return;
  middlewareDispatchFns.set(reducerPath, middleware(store));
};
const removeMiddleware = (reducerPath) => {
  middlewareDispatchFns.delete(reducerPath);
};
const resetMiddlewares = () => {
  middlewareDispatchFns.clear();
};
export {
  addMiddleware,
  queryMiddleware,
  removeMiddleware,
  resetMiddlewares
};
