import { jsx } from "react/jsx-runtime";
import { createManager } from "redux-injectors";
import enums from "../utils/constants.js";
import { authReducer } from "../data/auth/reducer.js";
import { authentication } from "../sideeffect/auth/index.js";
import { Login } from "./login/index.js";
import { endSession, isUserAuthorized } from "../utils/auth/index.js";
import { httpClientProps } from "../communication/http-client/props.js";
import { setLoginParams } from "../utils/auth/loginParams.js";
const key = "auth";
const RequireAuth = ({
  children,
  clientId = enums.CLIENT_ID,
  scope = "loc",
  responseType = "code",
  isConsumerUser = false
}) => {
  const AuthManager = createManager({
    name: "AuthManager",
    key,
    reducer: authReducer,
    saga: authentication
  });
  httpClientProps.endSession = endSession;
  const userAuthorized = isUserAuthorized();
  if (userAuthorized) {
    setLoginParams({ clientId, scope, responseType });
    return /* @__PURE__ */ jsx(AuthManager, { children });
  }
  return /* @__PURE__ */ jsx(AuthManager, { children: /* @__PURE__ */ jsx(
    Login,
    {
      clientId,
      scope,
      responseType,
      isConsumerUser,
      children
    }
  ) });
};
export {
  RequireAuth
};
