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