import { u as d, F as g } from "./FetchConfigsUtils-476a602b.mjs";
import { u as k, a as E } from "./useUserInfo-ad7006e5.mjs";
import e, { useEffect as y } from "react";
import { IamUserAuthorizationClient as N } from "@accelbyte/sdk-iam";
import { A as l } from "./Alert-c2425f39.mjs";
import { C as A } from "./CommonError-e27d39d7.mjs";
import { A as m } from "./Alert-1277e378.mjs";
import { U as u } from "./ProfileImage-6c73026b.mjs";
import { ERROR_LINK_ANOTHER_3RD_PARTY_ACCOUNT as h } from "@accelbyte/sdk";
import { Trans as c } from "react-i18next";
import { B as f, b as P, c as D } from "./Button-c97a7217.mjs";
import { D as L, a as b, b as U } from "./Dialog-b2e1c8bb.mjs";
import { t as T } from "./i18n-c7e26598.mjs";
import { u as C } from "./useDiscoveryConfigs-cf63cd60.mjs";
const j = ({ children: o }) => {
  const {
    state: { user: a, userFetchStatus: t }
  } = k(), { state: n } = E(), [r] = d();
  return y(() => {
    if (!a && t !== g.FETCHING) {
      const s = new N(r).createLoginURL(n.location.pathname);
      window.location.replace(s);
    }
  }, []), /* @__PURE__ */ e.createElement(e.Fragment, null, o);
}, G = (o) => {
  const { error: a, accountConflictInformation: t, onDismiss: n } = o;
  if ((t == null ? void 0 : t.errorCode) === h && (t != null && t.previousLinkedPlatformAccount)) {
    const { platformID: r, platformUserID: s, platformDisplayName: i } = t.previousLinkedPlatformAccount, p = u.getPlatformName(r);
    return /* @__PURE__ */ e.createElement(l, { className: "mb-6", type: m.danger, onDismiss: n }, /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkedAccountpage.cannotLinkWithAnotherAccount" }, "Unable to link this ", { platformName: p }, " account. Please link the ", { platformName: p }, " account previously linked to this account :", " ", { platformDisplayName: i }, " ( ", { platformUserID: s }, " )."));
  }
  if (t) {
    const r = u.getPlatformName(t.platformId);
    return /* @__PURE__ */ e.createElement(l, { className: "mb-6", type: m.danger, onDismiss: n }, /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkedAccountPage.linkConflictError" }, "That ", { platformName: r }, " account has already been linked with another account.", /* @__PURE__ */ e.createElement("br", null), " Please contact support for assistance linking it with a different account."));
  }
  return a ? /* @__PURE__ */ e.createElement(l, { type: m.danger, className: "alert", onDismiss: n }, /* @__PURE__ */ e.createElement(A, { error: a })) : null;
};
const X = ({ onCancel: o, onConfirm: a, platformId: t }) => {
  var i;
  const { state: n } = C(), r = u.getPlatformName(t), s = ((i = n.discoveryConfigData) == null ? void 0 : i.brandName.data.value) || "";
  return /* @__PURE__ */ e.createElement(L, { className: "purchaseDialog", title: T("LinkedAccountPage.confirmUnlinkDialog.title"), isOpen: !0 }, /* @__PURE__ */ e.createElement(b, null, /* @__PURE__ */ e.createElement("p", { className: "dialogPlatformBodyText" }, /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkedAccountPage.confirmUnlinkDialog.unlinkConfirm" }, "Do you want to unlink your ", /* @__PURE__ */ e.createElement("span", { className: "capitalize" }, { platformName: r }), " account from", { publisherName: s }, "?"))), /* @__PURE__ */ e.createElement(U, null, /* @__PURE__ */ e.createElement("div", { className: "flex justify-end" }, /* @__PURE__ */ e.createElement(
    f,
    {
      className: "btn btn-ghost mr-2 uppercase",
      buttonType: P.TEXT,
      buttonStyle: D.NONE,
      onClick: () => {
        o && o();
      }
    },
    /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkAccountPage.cancel" }, "Cancel")
  ), /* @__PURE__ */ e.createElement(
    f,
    {
      className: "btn btn-primary uppercase",
      onClick: () => {
        a && a();
      }
    },
    /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkAccountPage.unlink" }, "Unlink")
  ))));
};
export {
  G as L,
  j as P,
  X as U
};
