import { u as shortid, a as Ctx, D as DesktopChecker, G as GlobalPath, U as UrlUtils, v as LoginPath, L as Loading, w as LoadingSize, i as CommonError } from "./index.js";
import React__default, { Component } from "react";
import { s as styles } from "./URLGenerator.module.js";
import "./validator.js";
import "./dateFns.js";
import "./reactPlayer.js";
import "react-router-dom";
import "./reactSlick.js";
class RegisterUrlGenerator extends Component {
  constructor(props) {
    super(props);
    this.randString = shortid();
    this.state = { error: null };
    this.randString = shortid();
    this.appState = Ctx.getAppState();
  }
  componentDidMount() {
    this.tryRegister();
  }
  async tryRegister() {
    try {
      if (DesktopChecker.isDesktopApp()) {
        const appState = this.appState;
        if (appState.getUser() !== null)
          return appState.state.appHistory.replace(GlobalPath.Home.link);
        const params = UrlUtils.silentSearchParamsBuilder(appState.state.appHistory.location.search);
        const returnPath = params.get(LoginPath.LoginURLGeneratorParamKeys.RETURN_PATH_PARAMS_KEY);
        const randStringInParams = params.get(LoginPath.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY);
        if (randStringInParams && randStringInParams !== this.randString) {
          params.delete(LoginPath.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY);
          appState.state.appHistory.replace(`${returnPath || GlobalPath.Home.link}`);
          return;
        }
        params.set(LoginPath.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY, this.randString);
        appState.state.appHistory.replace(`${UrlUtils.makeAbsolutePath(appState.state.appHistory.location.pathname)}?${params.toString()}`);
        const registerURL = Ctx.getAppState().getSdk().IAM.UserAuthorization().createLoginURL(null, "register");
        window.location.replace(registerURL);
      }
    } catch (error) {
      this.setState({ error });
    }
  }
  render() {
    const { error } = this.state;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: styles.registerURLGenerator
    }, !error && /* @__PURE__ */ React__default.createElement(Loading, {
      className: LoadingSize.tall
    }), error && /* @__PURE__ */ React__default.createElement(CommonError, {
      error
    }));
  }
}
export { RegisterUrlGenerator as default };
