import { r as registerInstance, h as h$1, c as Host } from './index-38ad4957.js';
import { f as useEffect, n as h } from './dom-context-hooks.module-50442785.js';
import { J, k as kn, j as jn, i as isDemo } from './index.module-b23fdad8.js';

function usePortalProtectedRoute({ requireEmailVerification, redirectTo, redirectToUnverified, }) {
  var _a;
  const userIdent = J();
  const authenticated = !!(userIdent === null || userIdent === void 0 ? void 0 : userIdent.jwt);
  const emailVerified = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.emailVerified;
  const { pathname, search } = kn();
  const nextPageParam = new URLSearchParams();
  nextPageParam.append("nextPage", `${pathname}${search}`);
  useEffect(() => {
    if (!authenticated) {
      return jn.push({
        pathname: redirectTo,
        search: "?" + nextPageParam.toString(),
      });
    }
    if (requireEmailVerification && !emailVerified) {
      return jn.push({
        pathname: redirectToUnverified || redirectTo,
        search: "?" + nextPageParam.toString(),
      });
    }
  }, []);
  return !!userIdent;
}

const PortalProtectedRoute = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.ignored = true;
    /**
     * Redirect participants to this page they are not logged in.
     *
     * @uiName Unauthenticated participant redirect
     */
    this.redirectTo = "/";
    /**
     * @uiName Require email verification
     */
    this.requireEmailVerification = false;
    /**
     * Redirect participants to this page when email verification is required but they have not verified their email.
     *
     * @uiName Unverified participant redirect
     */
    this.redirectToUnverified = "/emailVerification";
    h(this);
  }
  disconnectedCallback() { }
  render() {
    const hasUser = isDemo()
      ? usePortalProtectedRouteDemo()
      : usePortalProtectedRoute(this);
    return (h$1(Host, { style: { display: hasUser ? "contents" : "none" } }, h$1("slot", null)));
  }
};
function usePortalProtectedRouteDemo({}) {
  return true;
}

export { PortalProtectedRoute as sqm_portal_protected_route };
