import { Alert as T } from "./accelbyte-widgets123.mjs";
import { Typography as k } from "./accelbyte-widgets173.mjs";
import { LanguageSelector as w } from "./accelbyte-widgets162.mjs";
import { Tabs as N, TabStyles as A } from "./accelbyte-widgets174.mjs";
import { t as f } from "./accelbyte-widgets58.mjs";
import { UIEvent as y } from "./accelbyte-widgets138.mjs";
import { Ctx as E } from "./accelbyte-widgets33.mjs";
import { REGISTRATION_LINK_ACCOUNT_EMAIL_STORAGE_KEY as b } from "./accelbyte-widgets175.mjs";
import { GlobalPath as L } from "./accelbyte-widgets104.mjs";
import { LoginPath as S } from "./accelbyte-widgets35.mjs";
import { FeUtils as v } from "./accelbyte-widgets45.mjs";
import { DesktopChecker as d } from "@accelbyte/sdk";
import C from "./accelbyte-widgets140.mjs";
import u from "classnames";
import { LoginInProgress as x } from "./accelbyte-widgets176.mjs";
import * as e from "react";
import { Trans as h } from "react-i18next";
import { InputValidationOutdatedModal as I } from "./accelbyte-widgets141.mjs";
import { LinkExistingAccount as O } from "./accelbyte-widgets177.mjs";
import { LinkNewAccount as F } from "./accelbyte-widgets178.mjs";
import o from "./accelbyte-widgets179.mjs";
class D extends e.Component {
  constructor(n) {
    super(n), this.appState = E.getAppState();
  }
  render() {
    var t, a;
    const n = (t = this.props) != null && t.logo ? (a = this.props) == null ? void 0 : a.logo : this.appState.getCompanyLogo("header");
    return /* @__PURE__ */ e.createElement("div", { className: "logoContainer flex flex-shrink-0 flex-grow-0 items-center justify-center" }, /* @__PURE__ */ e.createElement("div", { className: "logo" }, n && /* @__PURE__ */ e.createElement("img", { src: n, className: "h-[54px] w-[256px] object-contain", alt: "logo", loading: "lazy" })));
  }
}
var P = /* @__PURE__ */ ((s) => (s.linkExistingAccount = "linkExistingAccount", s.linkNewAccount = "linkNewAccount", s))(P || {});
class oe extends e.Component {
  constructor(n) {
    super(n), this.getSearchParams = () => {
      var g;
      const t = (g = this.props) == null ? void 0 : g.isPreviewMode, a = this.appState.state.appHistory, i = v.getSearchParamsObject(a), r = t ? "preview" : i.get("alreadyLinked"), c = t ? "preview" : i.get("linkingToken"), p = t ? "preview" : i.get("platformId"), l = t ? "preview" : i.get("clientId");
      return {
        alreadyLinked: r,
        linkingToken: c,
        platformId: p,
        clientId: l
      };
    }, this.hideTitleAndTabs = (t) => {
      this.setState({ hideTitleAndTabs: t });
    }, this.setAlert = (t) => {
      this.setState({ alert: t });
    }, this.closeAlert = () => {
      this.setState({ alert: null });
    }, this.backToLogin = () => {
      this.appState.state.appHistory.replace(S.Login.makePath());
    }, this.toggleOpenForgotPassword = () => {
      this.setState({ isOpenForgotPassword: !this.state.isOpenForgotPassword });
    }, console.log("the props", this.props.selectedTab), this.state = {
      selectedTab: this.props.selectedTab === "linkNewAccount" ? "linkNewAccount" : "linkExistingAccount",
      hideTitleAndTabs: !1,
      alert: null,
      isOpenForgotPassword: !1
    }, this.appState = E.getAppState();
  }
  componentDidMount() {
    y.updateBackground(`url(${C})`);
    const n = this.appState.getUser(), { alreadyLinked: t, linkingToken: a, platformId: i, clientId: r } = this.getSearchParams();
    if (t === "true" || !a || !i || !r || n)
      return this.appState.state.appHistory.replace(L.Home.link);
    sessionStorage.getItem(b) && this.setState({
      hideTitleAndTabs: !0,
      selectedTab: "linkNewAccount"
    });
  }
  render() {
    var g;
    const { selectedTab: n, hideTitleAndTabs: t, alert: a, isOpenForgotPassword: i } = this.state, { linkingToken: r, platformId: c, clientId: p } = this.getSearchParams(), { isPreviewMode: l } = this.props;
    return i ? /* @__PURE__ */ e.createElement("div", { className: u(o.linkPlatformAccountPage, { [o.desktop]: d.isDesktopApp() }) }, /* @__PURE__ */ e.createElement(x, { onRetry: this.toggleOpenForgotPassword })) : !r || !c || !p ? /* @__PURE__ */ e.createElement("div", null) : /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "row mr-3 mt-8" }, /* @__PURE__ */ e.createElement(w, { className: o.languageSelector, isDisabled: l })), /* @__PURE__ */ e.createElement("div", { className: u(o.linkPlatformAccountPage, { [o.desktop]: d.isDesktopApp() }) }, /* @__PURE__ */ e.createElement("div", { className: o.linkPlatformAccountContainer }, /* @__PURE__ */ e.createElement(D, { logo: (g = this.props) == null ? void 0 : g.logo }), /* @__PURE__ */ e.createElement("div", { className: o.headlessAccountContainerForm }, !t && /* @__PURE__ */ e.createElement("div", { className: o.contentWrapper }, /* @__PURE__ */ e.createElement(k, { tag: "h3", fontSize: "lg", isCentered: !0, className: o.title }, /* @__PURE__ */ e.createElement(h, { i18nKey: "LinkPlatformAccountPage.title" }, "Link an Account")), /* @__PURE__ */ e.createElement(k, { tag: "p", fontSize: "2sm", isCentered: !0, className: o.titleDescription }, /* @__PURE__ */ e.createElement(h, { i18nKey: "LinkPlatformAccountPage.titleDescription" }, "Sorry, we were not able to find any account that is already linked with this account. Would you like to link instead?"))), /* @__PURE__ */ e.createElement("div", { className: o.formWrapper }, !t && /* @__PURE__ */ e.createElement(N, null, Object.keys(P).map((m) => /* @__PURE__ */ e.createElement(
      "span",
      {
        className: u(A.tab, m === n && A.active, o.formTabs),
        onClick: () => l ? {} : this.setState({
          selectedTab: m
        }),
        key: m
      },
      H(m)
    ))), a && /* @__PURE__ */ e.createElement("div", { className: "mt-6" }, /* @__PURE__ */ e.createElement(T, { type: a.type, onDismiss: this.closeAlert }, a.message)), /* @__PURE__ */ e.createElement("div", { className: "py-6" }, n === "linkExistingAccount" && /* @__PURE__ */ e.createElement(
      O,
      {
        setAlert: this.setAlert,
        backToLogin: this.backToLogin,
        linkingToken: r,
        platformId: c,
        clientId: p,
        isPreviewMode: l,
        onOpenForgotPassword: d.isDesktopApp() ? this.toggleOpenForgotPassword : void 0
      }
    ), n === "linkNewAccount" && /* @__PURE__ */ e.createElement(
      F,
      {
        linkingToken: r,
        platformId: c,
        clientId: p,
        isPreviewMode: l,
        onContinueToRegistrationForm: (m) => this.hideTitleAndTabs(m)
      }
    ))), !t && /* @__PURE__ */ e.createElement("div", { className: o.bottomSection }, /* @__PURE__ */ e.createElement("p", { className: o.loginWithAccelByteAccount }, /* @__PURE__ */ e.createElement(h, { i18nKey: "LinkPlatformAccountPage.loginWithAnotherAccount" }, "Don't want to link this account?", /* @__PURE__ */ e.createElement("br", null), /* @__PURE__ */ e.createElement("a", { href: "#", onClick: this.backToLogin }, "Login with AccelByte account"))))), t && /* @__PURE__ */ e.createElement("div", { className: "mt-5 cursor-pointer text-center", onClick: this.backToLogin }, "Back to login"), /* @__PURE__ */ e.createElement(I, null))));
  }
}
function H(s) {
  switch (s) {
    case "linkExistingAccount":
      return f("LinkPlatformAccountPage.tab.linkExistingAccount");
    case "linkNewAccount":
      return f("LinkPlatformAccountPage.tab.linkNewAccount");
    default:
      return "";
  }
}
export {
  D as HeaderLogoContainer,
  oe as default
};
