import { CommonError as u } from "./accelbyte-widgets124.mjs";
import { Loading as h } from "./accelbyte-widgets136.mjs";
import { Ctx as m } from "./accelbyte-widgets33.mjs";
import E from "classnames";
import e from "react";
import n from "./accelbyte-widgets226.mjs";
import { PreviewLinkedAccounts as k } from "./accelbyte-widgets227.mjs";
import { PreviewMyGames as M } from "./accelbyte-widgets228.mjs";
import { mockUserLinkedPlatform as P, mockUserGameEntitlementRecord as v, mockUserGameInfoRecord as I } from "./accelbyte-widgets209.mjs";
class U extends e.Component {
  constructor(t) {
    super(t), this.state = {
      error: null
    }, this.gameManager = m.getAppState().gameManager, this.gameManager.subscribe(() => this.setState({})), this.linkedAccountsManager = m.getAppState().linkAccountManager, this.linkedAccountsManager.subscribe(() => this.setState({}));
  }
  async componentDidMount() {
    var r;
    if (this.props.isPreviewMode)
      return;
    const t = (r = m.getAppState().getUser()) == null ? void 0 : r.userId;
    if (t)
      try {
        this.setState({ error: null });
        const [, a] = await Promise.all([
          this.linkedAccountsManager.getUserDistinctLinkedPlatform(t),
          this.gameManager.fetchGameEntitlements(t)
        ]);
        if (a) {
          const s = a.map((o) => o.appId).filter(Boolean);
          await this.gameManager.fetchGamesInfo(s);
        }
      } catch (a) {
        this.setState({ error: a });
      }
  }
  render() {
    const {
      gameEntitlementsRecord: t,
      gameInfoRecord: r,
      isFetchingGameInfo: a,
      isFetchingGameEntitlements: s
    } = this.gameManager.state, { linkedPlatform: o, isFetching: l } = this.linkedAccountsManager.state, { error: c } = this.state, g = s || l || a, i = this.props.isPreviewMode, d = i ? P : o, f = i ? v : t, p = i ? I : r;
    return /* @__PURE__ */ e.createElement("main", { className: E(n.accountOverviewPage) }, g ? /* @__PURE__ */ e.createElement("div", { className: n.loadingContainer }, /* @__PURE__ */ e.createElement(h, null)) : /* @__PURE__ */ e.createElement(e.Fragment, null, c && /* @__PURE__ */ e.createElement("div", { className: n.errorContainer }, /* @__PURE__ */ e.createElement(u, { error: c })), /* @__PURE__ */ e.createElement("div", { className: n.myGamesContainer }, /* @__PURE__ */ e.createElement(M, { gameEntitlementsRecord: f || null, gameInfoRecord: p || null })), /* @__PURE__ */ e.createElement("div", { className: n.linkedPlatformContainer }, /* @__PURE__ */ e.createElement(k, { linkedPlatform: d }))));
  }
}
export {
  U as default
};
