import { Alert as c } from "./accelbyte-widgets123.mjs";
import { CommonError as s } from "./accelbyte-widgets124.mjs";
import { Dialog as m, DialogBody as d } from "./accelbyte-widgets235.mjs";
import { ArrowIcon as f } from "./accelbyte-widgets125.mjs";
import { LoadingBarIcon as h } from "./accelbyte-widgets342.mjs";
import { t as g } from "./accelbyte-widgets58.mjs";
import { Ctx as p } from "./accelbyte-widgets33.mjs";
import { AlertType as u } from "./accelbyte-widgets128.mjs";
import { LinkedPlatformId as P } from "./accelbyte-widgets239.mjs";
import { Iam as y } from "@accelbyte/sdk-iam";
import t from "react";
import { Trans as a } from "react-i18next";
import "./accelbyte-widgets274.mjs";
import { getThirdPartyPlatformIcon as L } from "./accelbyte-widgets275.mjs";
import { mockThirdPartyLogin as E } from "./accelbyte-widgets209.mjs";
import { AllowedThirdPartyClient as C } from "./accelbyte-widgets78.mjs";
import { DesktopChecker as k } from "@accelbyte/sdk";
class R extends t.Component {
  constructor(n) {
    super(n), this.fetchThirdPartyLoginConfig = async () => {
      if (!this.state.isFetchingThirdPartyLoginConfig) {
        this.setState({ isFetchingThirdPartyLoginConfig: !0, fetchThirdPartyLoginConfigError: null });
        try {
          const i = (await y.ThirdPartyCredentialApi(p.getAppState().getSdk()).getPlatformsClientsActive()).filter(
            (e) => !!C.enum[e.PlatformId] && e.IsActive
          );
          this.setState({ thirdPartyLoginConfig: i });
        } catch (r) {
          console.error(r), this.setState({ fetchThirdPartyLoginConfigError: r });
        } finally {
          this.setState({ isFetchingThirdPartyLoginConfig: !1 });
        }
      }
    }, this.renderPlatformList = () => {
      const { isPreviewMode: r } = this.props, { thirdPartyLoginConfig: o } = this.state, i = r ? E : o;
      return i.length < 1 ? /* @__PURE__ */ t.createElement("div", { className: "platformBox disabled text-center" }, /* @__PURE__ */ t.createElement(a, { i18nKey: "LinkedAccountPage.linkAccount.modal.noPlatformConfig" }, "No third party platform available")) : i.map((e) => {
        const l = this.props.linkedPlatform.has(e.PlatformId);
        return l || !e.IsActive || k.isDesktopApp() && e.PlatformId === P.enum.oculusweb ? null : /* @__PURE__ */ t.createElement(
          "div",
          {
            onClick: () => {
              this.props.openConfirmLinkToPlatformDialog(e);
            },
            role: "button",
            key: e.PlatformId,
            className: "platformBox"
          },
          /* @__PURE__ */ t.createElement("span", { className: "platform flex items-center capitalize" }, L(e.PlatformId)),
          !l && /* @__PURE__ */ t.createElement(f, null),
          l && /* @__PURE__ */ t.createElement("span", { className: "text-green-40 uppercase" }, /* @__PURE__ */ t.createElement(a, { i18nKey: "LinkAccountDialog.linked" }, "Linked"))
        );
      });
    }, this.state = {
      thirdPartyLoginConfig: [],
      isFetchingThirdPartyLoginConfig: !1,
      fetchThirdPartyLoginConfigError: null,
      fetchThirdPartyLoginUrlError: null
    };
  }
  componentDidMount() {
    this.props.isPreviewMode || this.fetchThirdPartyLoginConfig();
  }
  render() {
    const { onClose: n, isPreviewMode: r } = this.props, { isFetchingThirdPartyLoginConfig: o, fetchThirdPartyLoginConfigError: i, fetchThirdPartyLoginUrlError: e } = this.state;
    return /* @__PURE__ */ t.createElement(
      m,
      {
        className: "purchaseDialog",
        title: g("LinkedAccountPage.title"),
        isOpen: !0,
        onClose: () => {
          n && n();
        },
        isPreviewMode: r
      },
      /* @__PURE__ */ t.createElement(d, null, /* @__PURE__ */ t.createElement("div", { className: "dialogPlatformBodyText" }, o && /* @__PURE__ */ t.createElement("div", { className: "text-center" }, /* @__PURE__ */ t.createElement(h, null)), !o && !!i && /* @__PURE__ */ t.createElement("div", { className: "text-center" }, /* @__PURE__ */ t.createElement(a, { i18nKey: "LinkedAccountPage.linkAccount.modal.fetchConfigFail" }, "Unable to get third party platform information ", /* @__PURE__ */ t.createElement("br", null), /* @__PURE__ */ t.createElement("a", { role: "button", onClick: this.fetchThirdPartyLoginConfig }, "Try Again"))), !o && !i && /* @__PURE__ */ t.createElement(t.Fragment, null, e && /* @__PURE__ */ t.createElement(c, { className: "mb-6", type: u.danger }, /* @__PURE__ */ t.createElement(s, { error: e })), /* @__PURE__ */ t.createElement(a, { i18nKey: "LinkedAccountPage.linkAccountDialog" }, "Select the platform you want to link to your account."), /* @__PURE__ */ t.createElement("div", { className: "dialogPlatformList" }, this.renderPlatformList()))))
    );
  }
}
export {
  R as LinkAccountDialog
};
