import { CommonError as S } from "./accelbyte-widgets124.mjs";
import { ArrowIcon as P, ArrowIconStyles as y } from "./accelbyte-widgets125.mjs";
import { Loading as x } from "./accelbyte-widgets136.mjs";
import { OverrideCSS as k } from "./accelbyte-widgets78.mjs";
import { Ctx as w } from "./accelbyte-widgets33.mjs";
import { AccPath as t } from "./accelbyte-widgets34.mjs";
import { UrlUtils as b } from "./accelbyte-widgets90.mjs";
import l from "classnames";
import e from "react";
import { Trans as d } from "react-i18next";
import { NavLink as N, Switch as M, Route as f, Redirect as I } from "react-router-dom";
import { GameItem as K } from "./accelbyte-widgets430.mjs";
import i from "./accelbyte-widgets431.mjs";
import { PurchasedItemsListLogic as O } from "./accelbyte-widgets502.mjs";
import { PurchasedKeys as A } from "./accelbyte-widgets503.mjs";
import { PurchasedOptionbox as C } from "./accelbyte-widgets504.mjs";
import { mockUserPurchasedGameMap as U, mockUserPurchasedGameList as v } from "./accelbyte-widgets209.mjs";
const F = () => /* @__PURE__ */ e.createElement("p", { className: l(i.noGame, k.TITLE_FONT) }, /* @__PURE__ */ e.createElement(d, { i18nKey: "MyGameList.noGame" }, "You don't have any games yet."));
class te extends e.Component {
  constructor(s) {
    var o;
    super(s), this.renderMyGames = () => {
      const { isFetching: c, gameList: m, gameItems: r } = this.logic.state, a = this.props.isPreviewMode, p = a ? v : m, E = a ? U() : r;
      return /* @__PURE__ */ e.createElement(e.Fragment, null, !c && p && /* @__PURE__ */ e.createElement("div", { className: i.myGameList }, p.length && E && E.size ? p.map((G) => {
        const { itemId: L } = G, g = L && E.get(L);
        return g ? /* @__PURE__ */ e.createElement(K, { key: g.itemId, item: g }) : null;
      }) : /* @__PURE__ */ e.createElement(F, null)));
    }, this.renderPurchasedItemsSidebar = () => {
      const c = this.props.isPreviewMode;
      return /* @__PURE__ */ e.createElement("div", { className: i.sidebarContainer }, /* @__PURE__ */ e.createElement("div", { className: "sidebar" }, /* @__PURE__ */ e.createElement("nav", { className: "navigationDesktop" }, /* @__PURE__ */ e.createElement(N, { className: c ? "active" : "", exact: !0, to: t.PurchasedGame.makePath() }, /* @__PURE__ */ e.createElement("span", null, /* @__PURE__ */ e.createElement(d, { i18nKey: "MyGameList.tabs.games" }, "Games")), /* @__PURE__ */ e.createElement(P, { className: l("activeArrow", y.right) })), /* @__PURE__ */ e.createElement(N, { exact: !0, to: t.PurchasedKeys.makePath() }, /* @__PURE__ */ e.createElement("span", null, /* @__PURE__ */ e.createElement(d, { i18nKey: "MyGameList.tabs.keys" }, "Keys")), /* @__PURE__ */ e.createElement(P, { className: l("activeArrow", y.right) })), /* @__PURE__ */ e.createElement(N, { exact: !0, to: t.PurchasedOptionbox.makePath() }, /* @__PURE__ */ e.createElement("span", null, /* @__PURE__ */ e.createElement(d, { i18nKey: "MyGameList.tabs.optionbox" }, "Optionbox")), /* @__PURE__ */ e.createElement(P, { className: l("activeArrow", y.right) })))), /* @__PURE__ */ e.createElement("div", { className: "purchasedItemsContainer" }, c && this.renderMyGames(), /* @__PURE__ */ e.createElement(M, null, /* @__PURE__ */ e.createElement(f, { exact: !0, path: t.PurchasedGame.link, render: this.renderMyGames }), /* @__PURE__ */ e.createElement(
        f,
        {
          exact: !0,
          path: t.PurchasedKeys.link,
          render: (m) => {
            const r = Number(b.silentSearchParamsBuilder(m.location.search).get("page")), a = !Number.isNaN(r) && r >= 1;
            return a ? a && /* @__PURE__ */ e.createElement(A, { page: r }) : /* @__PURE__ */ e.createElement(I, { to: t.PurchasedKeys.withSearchParams({ page: 1 }) });
          }
        }
      ), /* @__PURE__ */ e.createElement(
        f,
        {
          exact: !0,
          path: t.PurchasedOptionbox.link,
          render: (m) => {
            const r = Number(b.silentSearchParamsBuilder(m.location.search).get("page")), a = !Number.isNaN(r) && r >= 1;
            return a ? a && /* @__PURE__ */ e.createElement(C, { page: r }) : /* @__PURE__ */ e.createElement(I, { to: t.PurchasedOptionbox.withSearchParams({ page: 1 }) });
          }
        }
      ), /* @__PURE__ */ e.createElement(I, { from: t.PurchasedItems.makePath(), to: t.PurchasedGame.makePath() }))));
    };
    const { limit: n } = s, h = ((o = w.getAppState().getUser()) == null ? void 0 : o.userId) || null, u = new O({ userId: h, limit: n });
    this.state = {
      isProductKeyDialogOpen: !1
    }, u.subscribe(() => this.setState({})), this.logic = u;
  }
  componentDidMount() {
    this.props.isPreviewMode || this.logic.init();
  }
  render() {
    const { isFetching: s, error: n, gameList: h } = this.logic.state, o = this.props.isPreviewMode ? v : h;
    return /* @__PURE__ */ e.createElement("div", { className: i.purchasedItemsListWrapper }, s && /* @__PURE__ */ e.createElement(x, null), !s && n && /* @__PURE__ */ e.createElement("div", { className: i.errorContainer }, /* @__PURE__ */ e.createElement(S, { error: n })), !s && o && this.renderPurchasedItemsSidebar());
  }
}
export {
  F as NoGame,
  te as PurchasedItemsList
};
