import { u as shortid, a as Ctx, G as GlobalPath, U as UrlUtils, v as LoginPath, L as Loading, w as LoadingSize, T as Trans, i as CommonError } from "./index.js";
import React__default 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 LoginURLGenerator extends React__default.Component {
  constructor(props) {
    super(props);
    this.randString = shortid();
    this.state = { error: null };
    this.randString = shortid();
    this.appState = Ctx.getAppState();
  }
  componentDidMount() {
    this.tryLogin();
  }
  tryLogin() {
    const appState = this.appState;
    const { appHistory } = appState.state;
    const isLogin = !!appState.getUser();
    const sdk = appState.getSdk();
    if (isLogin) {
      return appHistory.replace(GlobalPath.Home.link);
    }
    const params = UrlUtils.silentSearchParamsBuilder(appHistory.location.search);
    const returnPath = params.get(LoginPath.LoginURLGeneratorParamKeys.RETURN_PATH_PARAMS_KEY);
    appHistory.replace(`${UrlUtils.makeAbsolutePath(appHistory.location.pathname)}?${params.toString()}`);
    const { createLoginURL } = sdk.IAM.UserAuthorization();
    const loginURL = createLoginURL(returnPath);
    window.location.replace(loginURL);
  }
  render() {
    const { error } = this.state;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: styles.loginURLGenerator
    }, !error && /* @__PURE__ */ React__default.createElement(Loading, {
      className: LoadingSize.tall
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "InitialUserFetchPage.notice"
    })), error && /* @__PURE__ */ React__default.createElement(CommonError, {
      error
    }));
  }
}
export { LoginURLGenerator as default };
