"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var render_with_state_addons_exports = {};
__export(render_with_state_addons_exports, {
  RenderWithStateAddOns: () => RenderWithStateAddOns
});
module.exports = __toCommonJS(render_with_state_addons_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_styled_components = require("styled-components");
var import_pui_theme = require("@elliemae/pui-theme");
var import_redux_injectors = require("redux-injectors");
const RenderWithStateAddOns = ({
  Component,
  reducer,
  saga,
  theme = (0, import_pui_theme.getDefaultTheme)(),
  ...rest
}) => {
  const [ready, setReady] = (0, import_react.useState)(false);
  if (Array.isArray(reducer)) {
    reducer.forEach((r) => (0, import_redux_injectors.useInjectReducer)(r));
  } else {
    (0, import_redux_injectors.useInjectReducer)(reducer);
  }
  if (Array.isArray(saga)) {
    saga.forEach((s) => (0, import_redux_injectors.useInjectSaga)(s));
  } else if (saga) {
    (0, import_redux_injectors.useInjectSaga)(saga);
  }
  (0, import_react.useEffect)(() => {
    setReady(true);
  }, []);
  return ready ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_styled_components.ThemeProvider, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...rest }) }) : null;
};
