"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 key2 of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key2) && key2 !== except)
        __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || 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 require_auth_exports = {};
__export(require_auth_exports, {
  RequireAuth: () => RequireAuth
});
module.exports = __toCommonJS(require_auth_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_redux_injectors = require("redux-injectors");
var import_constants = __toESM(require("../utils/constants.js"));
var import_reducer = require("../data/auth/reducer.js");
var import_auth = require("../sideeffect/auth/index.js");
var import_login = require("./login/index.js");
var import_auth2 = require("../utils/auth/index.js");
var import_props = require("../communication/http-client/props.js");
var import_loginParams = require("../utils/auth/loginParams.js");
const key = "auth";
const RequireAuth = ({
  children,
  clientId = import_constants.default.CLIENT_ID,
  scope = "loc",
  responseType = "code",
  isConsumerUser = false
}) => {
  const AuthManager = (0, import_redux_injectors.createManager)({
    name: "AuthManager",
    key,
    reducer: import_reducer.authReducer,
    saga: import_auth.authentication
  });
  import_props.httpClientProps.endSession = import_auth2.endSession;
  const userAuthorized = (0, import_auth2.isUserAuthorized)();
  if (userAuthorized) {
    (0, import_loginParams.setLoginParams)({ clientId, scope, responseType });
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthManager, { children });
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthManager, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_login.Login,
    {
      clientId,
      scope,
      responseType,
      isConsumerUser,
      children
    }
  ) });
};
