import { O as y, T as i, g as v, a as u, L as C, i as L } from "./index-162fd1aa.mjs";
import { c as m } from "./reactSlick-cb4a2d39.mjs";
import e from "react";
import { Link as k } from "react-router-dom";
import { g as w } from "./PlatformIcon-9c8dca6c.mjs";
import { p as _, G as N, N as G } from "./PurchasedItemsList-e6935889.mjs";
import { h as I, i as O, j as M } from "./MockVars-1cf2eb0a.mjs";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "./ItemHelper-37a12c2c.mjs";
import "./Pagination-a353297b.mjs";
import "./WithPropsGuard-9dd19ecc.mjs";
import "./default-item-image-9aab0e29.mjs";
const R = "accountOverviewPage _accountOverviewPage_7b419", B = "loadingContainer _loadingContainer_7d7c3", F = "errorContainer _errorContainer_d615b", H = "myGamesContainer _myGamesContainer_e1955", T = "linkedPlatformContainer _linkedPlatformContainer_53ea8", K = "subSection _subSection_4e66e", U = "subSectionHeader _subSectionHeader_aa444", x = "subSectionBody _subSectionBody_31ece", r = {
  accountOverviewPage: R,
  loadingContainer: B,
  errorContainer: F,
  myGamesContainer: H,
  linkedPlatformContainer: T,
  subSection: K,
  subSectionHeader: U,
  subSectionBody: x
}, p = ({ children: n, className: t }) => /* @__PURE__ */ e.createElement("div", { className: m(r.subSection, t) }, n), S = ({ children: n, className: t }) => /* @__PURE__ */ e.createElement("div", { className: m(r.subSectionBody, t) }, n), E = ({ children: n, className: t }) => /* @__PURE__ */ e.createElement("div", { className: m(r.subSectionHeader, t, y.TITLE_FONT) }, n), j = "linkedAccountsSubSection _linkedAccountsSubSection_18ad9", D = "previewLinkedAccount _previewLinkedAccount_22319", W = "noLinkedAccount _noLinkedAccount_ff07d", Y = "linkedAccountsContainer _linkedAccountsContainer_1273e", $ = "platform _platform_a0343", s = {
  linkedAccountsSubSection: j,
  previewLinkedAccount: D,
  noLinkedAccount: W,
  linkedAccountsContainer: Y,
  platform: $
}, q = (n) => {
  const { linkedPlatform: t } = n;
  return /* @__PURE__ */ e.createElement(p, { className: s.linkedAccountsSubSection }, /* @__PURE__ */ e.createElement(E, null, /* @__PURE__ */ e.createElement(i, { i18nKey: "AccountOverviewPage.subLinkedAccounts.title" }, "Linked Accounts"), /* @__PURE__ */ e.createElement(k, { to: v.LinkedAccounts.makePath() }, /* @__PURE__ */ e.createElement(i, { i18nKey: "AccountOverviewPage.subLinkedAccounts.seeAll" }, "See All"))), /* @__PURE__ */ e.createElement(S, null, /* @__PURE__ */ e.createElement("div", { className: s.previewLinkedAccount }, /* @__PURE__ */ e.createElement("table", null, /* @__PURE__ */ e.createElement("tbody", null, t && t.length > 0 ? t.map((a) => z(a)) : /* @__PURE__ */ e.createElement("tr", null, /* @__PURE__ */ e.createElement("td", { colSpan: 3, className: s.noLinkedAccount }, /* @__PURE__ */ e.createElement(i, { i18nKey: "LinkedAccountPage.noLinkedAccount" }, "You have no linked account"))))))));
}, z = (n) => {
  const t = n.platformName;
  return t ? /* @__PURE__ */ e.createElement("tr", { key: n.platformName }, /* @__PURE__ */ e.createElement("td", { className: s.linkedAccountsContainer }, /* @__PURE__ */ e.createElement("span", { className: s.platform }, w(t)))) : null;
}, J = (n) => {
  const { gameEntitlementsRecord: t, gameInfoRecord: a } = n;
  return /* @__PURE__ */ e.createElement(p, { className: _.myGamesSubSection }, /* @__PURE__ */ e.createElement(E, null, /* @__PURE__ */ e.createElement(i, { i18nKey: "AccountOverviewPage.subSectionGames.title" }, "My Games"), /* @__PURE__ */ e.createElement(k, { to: v.PurchasedGame.makePath() }, /* @__PURE__ */ e.createElement(i, { i18nKey: "AccountOverviewPage.subSectionGames.seeAll" }, "See all"))), /* @__PURE__ */ e.createElement(S, null, /* @__PURE__ */ e.createElement("div", { className: _.purchasedItemsListWrapper }, /* @__PURE__ */ e.createElement("div", { className: _.myGameList }, t ? Object.keys(t).map((o) => {
    const c = a && a[o];
    return c ? /* @__PURE__ */ e.createElement(N, { key: c == null ? void 0 : c.itemId, item: c }) : null;
  }) : /* @__PURE__ */ e.createElement(G, null)))));
};
class le extends e.Component {
  constructor(t) {
    super(t), this.state = {
      error: null
    }, this.gameManager = u.getAppState().gameManager, this.gameManager.subscribe(() => this.setState({})), this.linkedAccountsManager = u.getAppState().linkAccountManager, this.linkedAccountsManager.subscribe(() => this.setState({}));
  }
  async componentDidMount() {
    var a;
    if (this.props.isPreviewMode)
      return;
    const t = (a = u.getAppState().getUser()) == null ? void 0 : a.userId;
    if (t)
      try {
        this.setState({ error: null });
        const [, o] = await Promise.all([
          this.linkedAccountsManager.getUserDistinctLinkedPlatform(t),
          this.gameManager.fetchGameEntitlements(t)
        ]);
        if (o) {
          const c = o.map((l) => l.appId).filter(Boolean);
          await this.gameManager.fetchGamesInfo(c);
        }
      } catch (o) {
        this.setState({ error: o });
      }
  }
  render() {
    const {
      gameEntitlementsRecord: t,
      gameInfoRecord: a,
      isFetchingGameInfo: o,
      isFetchingGameEntitlements: c
    } = this.gameManager.state, { linkedPlatform: l, isFetching: f } = this.linkedAccountsManager.state, { error: g } = this.state, A = c || f || o, d = this.props.isPreviewMode, b = d ? I : l, P = d ? O : t, h = d ? M : a;
    return /* @__PURE__ */ e.createElement("main", { className: m(r.accountOverviewPage) }, A ? /* @__PURE__ */ e.createElement("div", { className: r.loadingContainer }, /* @__PURE__ */ e.createElement(C, null)) : /* @__PURE__ */ e.createElement(e.Fragment, null, g && /* @__PURE__ */ e.createElement("div", { className: r.errorContainer }, /* @__PURE__ */ e.createElement(L, { error: g })), /* @__PURE__ */ e.createElement("div", { className: r.myGamesContainer }, /* @__PURE__ */ e.createElement(J, { gameEntitlementsRecord: P || null, gameInfoRecord: h || null })), /* @__PURE__ */ e.createElement("div", { className: r.linkedPlatformContainer }, /* @__PURE__ */ e.createElement(q, { linkedPlatform: b }))));
  }
}
export {
  le as default
};
