import { c as d, u as g, F as k } from "./Env-92498313.mjs";
import { e as E, t as y, B as f, b as N, a as A } from "./useRoutes-367960a3.mjs";
import e, { useEffect as h } from "react";
import { IamUserAuthorizationClient as P } from "@accelbyte/sdk-iam";
import { A as i } from "./Alert-98fe02c6.mjs";
import { C as D } from "./CommonError-b56f12ad.mjs";
import { A as m } from "./Alert-1277e378.mjs";
import { U as u } from "./ProfileImage-64f9d3cd.mjs";
import { ERROR_LINK_ANOTHER_3RD_PARTY_ACCOUNT as L } from "@accelbyte/sdk";
import { Trans as c } from "react-i18next";
import { a as b, D as U, b as T, c as C } from "./index-28007ca6.mjs";
const x = ({ children: o }) => {
  const {
    state: { user: n, userFetchStatus: t }
  } = d(), { state: r } = E(), [a] = g();
  return h(() => {
    if (a && !n && t !== k.FETCHING) {
      const s = new P(a).createLoginURL(r.location.pathname);
      window.location.replace(s);
    }
  }, [a]), /* @__PURE__ */ e.createElement(e.Fragment, null, o);
}, z = (o) => {
  const { error: n, accountConflictInformation: t, onDismiss: r } = o;
  if ((t == null ? void 0 : t.errorCode) === L && (t != null && t.previousLinkedPlatformAccount)) {
    const { platformID: a, platformUserID: s, platformDisplayName: l } = t.previousLinkedPlatformAccount, p = u.getPlatformName(a);
    return /* @__PURE__ */ e.createElement(i, { className: "mb-6", type: m.danger, onDismiss: r }, /* @__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: l }, " ( ", { platformUserID: s }, " )."));
  }
  if (t) {
    const a = u.getPlatformName(t.platformId);
    return /* @__PURE__ */ e.createElement(i, { className: "mb-6", type: m.danger, onDismiss: r }, /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkedAccountPage.linkConflictError" }, "That ", { platformName: a }, " 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 n ? /* @__PURE__ */ e.createElement(i, { type: m.danger, className: "alert", onDismiss: r }, /* @__PURE__ */ e.createElement(D, { error: n })) : null;
};
const W = ({ onCancel: o, onConfirm: n, platformId: t }) => {
  var l;
  const { state: r } = b(), a = u.getPlatformName(t), s = ((l = r.discoveryConfigData) == null ? void 0 : l.brandName.data.value) || "";
  return /* @__PURE__ */ e.createElement(U, { className: "purchaseDialog", title: y("LinkedAccountPage.confirmUnlinkDialog.title"), isOpen: !0 }, /* @__PURE__ */ e.createElement(T, 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: a }), " account from", { publisherName: s }, "?"))), /* @__PURE__ */ e.createElement(C, null, /* @__PURE__ */ e.createElement("div", { className: "flex justify-end" }, /* @__PURE__ */ e.createElement(
    f,
    {
      className: "btn btn-ghost mr-2 uppercase",
      buttonType: N.TEXT,
      buttonStyle: A.NONE,
      onClick: () => {
        o && o();
      }
    },
    /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkAccountPage.cancel" }, "Cancel")
  ), /* @__PURE__ */ e.createElement(
    f,
    {
      className: "btn btn-primary uppercase",
      onClick: () => {
        n && n();
      }
    },
    /* @__PURE__ */ e.createElement(c, { i18nKey: "LinkAccountPage.unlink" }, "Unlink")
  ))));
};
export {
  z as L,
  x as P,
  W as U
};
