"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var store_exports = {};
__export(store_exports, {
  createAppStore: () => createAppStore,
  getStore: () => getStore,
  setStore: () => setStore
});
module.exports = __toCommonJS(store_exports);
var import_toolkit = require("@reduxjs/toolkit");
var import_react = require("@reduxjs/toolkit/query/react");
var import_redux_injectors = require("redux-injectors");
var import_redux_saga = __toESM(require("redux-saga"));
var import_reducers = require("./reducers.js");
var import_webpack_hmr = require("./webpack-hmr.js");
var import_queryMiddleware = require("./queryMiddleware.js");
var import_listenerMiddleware = require("./listenerMiddleware.js");
let rootReducer = (0, import_reducers.createReducer)();
let appStore = null;
const setStore = (store) => {
  appStore = store;
};
const getStore = () => appStore;
const createStore = (initialState, sagaMiddleware, history, middlewareConfig = {}, injectedReducers = {}) => {
  const { run: runSaga } = sagaMiddleware;
  const enhancers = [
    (0, import_redux_injectors.createInjectorsEnhancer)({
      createReducer: import_reducers.createReducer,
      runSaga
    })
  ];
  rootReducer = (0, import_reducers.createReducer)(injectedReducers);
  const baseStore = (0, import_toolkit.configureStore)({
    reducer: rootReducer,
    middleware: (getDefaultMiddleware) => getDefaultMiddleware(middlewareConfig).prepend(import_listenerMiddleware.listenerMiddleware.middleware).concat([sagaMiddleware, import_queryMiddleware.queryMiddleware]),
    devTools: true,
    preloadedState: initialState,
    enhancers
  });
  (0, import_react.setupListeners)(baseStore.dispatch);
  (0, import_webpack_hmr.enableHotReloading)(baseStore);
  return baseStore;
};
const createAppStore = (initialState = {}, history, middlewareConfig, injectedReducers) => {
  const sagaMiddleware = (0, import_redux_saga.default)({});
  const store = createStore(
    initialState,
    sagaMiddleware,
    history,
    middlewareConfig,
    injectedReducers
  );
  setStore(store);
  return store;
};
