import { CommonError as c } from "./accelbyte-widgets124.mjs";
import { Loading as g, LoadingSize as h } from "./accelbyte-widgets136.mjs";
import { Ctx as i } from "./accelbyte-widgets33.mjs";
import { GlobalPath as s } from "./accelbyte-widgets104.mjs";
import { LoginPath as r } from "./accelbyte-widgets35.mjs";
import { UrlUtils as n } from "./accelbyte-widgets90.mjs";
import { DesktopChecker as R } from "@accelbyte/sdk";
import a, { Component as d } from "react";
import p from "shortid";
import f from "./accelbyte-widgets137.mjs";
import { IamUserAuthorizationClient as S } from "@accelbyte/sdk-iam";
class k extends d {
  constructor(t) {
    super(t), this.randString = p(), this.state = { error: null }, this.randString = p(), this.appState = i.getAppState();
  }
  componentDidMount() {
    this.tryRegister();
  }
  async tryRegister() {
    try {
      if (R.isDesktopApp()) {
        const t = this.appState;
        if (t.getUser() !== null)
          return t.state.appHistory.replace(s.Home.link);
        const e = n.silentSearchParamsBuilder(t.state.appHistory.location.search), m = e.get(r.LoginURLGeneratorParamKeys.RETURN_PATH_PARAMS_KEY), o = e.get(r.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY);
        if (o && o !== this.randString) {
          e.delete(r.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY), t.state.appHistory.replace(`${m || s.Home.link}`);
          return;
        }
        e.set(r.LoginURLGeneratorParamKeys.RANDOM_NUMBER_KEY, this.randString), t.state.appHistory.replace(`${n.makeAbsolutePath(t.state.appHistory.location.pathname)}?${e.toString()}`);
        const l = new S(i.getAppState().getSdk()).createLoginURL(null, "register");
        window.location.replace(l);
      }
    } catch (t) {
      this.setState({ error: t });
    }
  }
  render() {
    const { error: t } = this.state;
    return /* @__PURE__ */ a.createElement("div", { className: f.registerURLGenerator }, !t && /* @__PURE__ */ a.createElement(g, { className: h.tall }), t && /* @__PURE__ */ a.createElement(c, { error: t }));
  }
}
export {
  k as default
};
