import { Breadcrumbs as M } from "./accelbyte-widgets190.mjs";
import { CommonError as S } from "./accelbyte-widgets204.mjs";
import { Lightbox as C } from "./accelbyte-widgets191.mjs";
import { LoadingPage as N } from "./accelbyte-widgets77.mjs";
import T from "./accelbyte-widgets210.mjs";
import { ItemHelper as k } from "./accelbyte-widgets192.mjs";
import { gaSendErrorEvent as x } from "./accelbyte-widgets145.mjs";
import { UIEvent as I } from "./accelbyte-widgets138.mjs";
import { Ctx as p } from "./accelbyte-widgets33.mjs";
import { FeatureDecodeError as w } from "./accelbyte-widgets149.mjs";
import { EcommerceErrorCode as G, ItemType as f, AppType as y } from "./accelbyte-widgets185.mjs";
import { EcomPath as B } from "./accelbyte-widgets59.mjs";
import { ErrorPath as K } from "./accelbyte-widgets69.mjs";
import { ErrorHelper as A } from "./accelbyte-widgets120.mjs";
import { PageTitleUtils as O } from "./accelbyte-widgets188.mjs";
import U from "./accelbyte-widgets140.mjs";
import { DecodeError as W } from "@accelbyte/sdk";
import e from "react";
import { Helmet as F } from "react-helmet";
import { Trans as l } from "react-i18next";
import { Link as _ } from "react-router-dom";
import { DiscountCountdownWidget as q } from "./accelbyte-widgets194.mjs";
import { AppDetailGallery as H } from "./accelbyte-widgets195.mjs";
import { CatalogItemBanner as R } from "./accelbyte-widgets196.mjs";
import $ from "./accelbyte-widgets197.mjs";
import { CatalogPurchaseWidget as D } from "./accelbyte-widgets198.mjs";
import j from "./accelbyte-widgets199.mjs";
import P from "./accelbyte-widgets212.mjs";
import { ItemDetailPurchaseAlert as z } from "./accelbyte-widgets202.mjs";
import J from "./accelbyte-widgets223.mjs";
import "./accelbyte-widgets201.mjs";
import { AppDetailPageLogic as Q } from "./accelbyte-widgets224.mjs";
import { PlatformRequirements as b } from "./accelbyte-widgets220.mjs";
import { mockSingleGameInfo as V } from "./accelbyte-widgets209.mjs";
const X = () => /* @__PURE__ */ e.createElement(N, { className: "mt-3 md:mt-7" }), Y = ({ error: o }) => {
  const r = () => {
    switch (!0) {
      case o instanceof w:
      case o instanceof W:
        return /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.item.decodeError" }, "The game data from the server is invalid. Please refresh the page.");
      default:
        return /* @__PURE__ */ e.createElement(S, { error: o });
    }
  };
  return /* @__PURE__ */ e.createElement("div", { className: "error" }, r());
};
class Z extends e.Component {
  constructor(r) {
    super(r), this.openLightbox = (h) => {
      this.setState({ isLightboxOpen: !0, selectedImagePosition: h });
    }, this.closeLightbox = () => {
      this.setState({ isLightboxOpen: !1 });
    };
    const i = p.getUserManager().state.user || void 0, a = i == null ? void 0 : i.country, { itemId: g, language: E } = r;
    this.logic = new Q({ itemId: g, country: a, user: i, language: E }), this.logic.subscribe(() => this.setState({})), this.state = {
      isLightboxOpen: !1,
      selectedImagePosition: 0
    };
  }
  componentDidMount() {
    this.props.isPreviewMode || (I.updateBackground(`url(${U})`), this.logic.init());
  }
  componentWillUnmount() {
    I.updateBackground(null);
  }
  render() {
    const r = p.getUserManager().state.user || void 0, { language: i, isPreviewMode: a } = this.props, { isLightboxOpen: g, selectedImagePosition: E } = this.state, { appItem: h, additionalAppInfo: m, itemPublishingContent: d, isFetching: v, error: c } = this.logic.state, { purchaseLogic: s } = this.logic, t = a ? V : h, u = k.getMedia(t, d), n = a ? a.isSingleGame : p.getAppState().isSingleGame();
    return c && A.extractServiceErrorCode(c) === G.ITEM_NOT_FOUND && x({ eventCategory: K.Error404.makePath(), eventLabel: A.errorToString(c) }), /* @__PURE__ */ e.createElement("div", { className: "itemDetailPage" }, /* @__PURE__ */ e.createElement(
      z,
      {
        purchaseLogic: s,
        user: r,
        isFetching: v,
        isPreviewMode: !!a
      }
    ), /* @__PURE__ */ e.createElement(F, null, t && /* @__PURE__ */ e.createElement("title", null, O.getPageTitle(p.getAppState().state.discovery || null, t.title, t.title))), v && /* @__PURE__ */ e.createElement(X, null), c && /* @__PURE__ */ e.createElement(Y, { error: c }), t && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(R, { item: t, itemPublishingContent: d, isPreviewMode: !!a }, !n && /* @__PURE__ */ e.createElement(M, null, /* @__PURE__ */ e.createElement(_, { to: B.GameList.makePath() }, /* @__PURE__ */ e.createElement(l, { i18nKey: "Navigation.links.games" }, "Games")), t.title), n && /* @__PURE__ */ e.createElement(
      D,
      {
        item: t,
        itemPublishingContent: d,
        purchaseLogic: s,
        additionalAppInfo: m,
        isPreviewMode: !!a
      }
    )), u && !n && /* @__PURE__ */ e.createElement(H, { itemMedias: u, openLightbox: this.openLightbox }), g && u && !n && /* @__PURE__ */ e.createElement(
      C,
      {
        itemMedias: u,
        isOpen: g,
        onClose: this.closeLightbox,
        selectedPosition: E
      }
    ), !n && /* @__PURE__ */ e.createElement("div", { className: "availableBundleContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.availableBundles.heading" }, "Available Bundles")), /* @__PURE__ */ e.createElement(
      P,
      {
        baseItem: t,
        itemType: f.enum.BUNDLE,
        language: i,
        initialShownItem: 4,
        noItemMessage: /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.availableBundles.noItem" }, "Looks like there are no items for this game yet.")
      }
    )), !n && /* @__PURE__ */ e.createElement("div", { className: "itemDetailContent" }, /* @__PURE__ */ e.createElement("div", { className: "description" }, /* @__PURE__ */ e.createElement($, { item: t }), m && /* @__PURE__ */ e.createElement(b, { className: "requirementsDesktop", additionalAppInfo: m })), /* @__PURE__ */ e.createElement("div", { className: "detailWidget" }, s && s.state.currencyMap && /* @__PURE__ */ e.createElement(j, { item: t }, /* @__PURE__ */ e.createElement(
      q,
      {
        item: t,
        currencyMap: s.state.currencyMap,
        position: "right",
        showDetail: !0
      }
    )), /* @__PURE__ */ e.createElement("div", { className: "protruded" }, /* @__PURE__ */ e.createElement(
      D,
      {
        item: t,
        itemPublishingContent: d,
        purchaseLogic: s,
        additionalAppInfo: m
      }
    )), m && /* @__PURE__ */ e.createElement(J, { additionalAppInfo: m })), m && /* @__PURE__ */ e.createElement(b, { className: "requirementsMobile", additionalAppInfo: m })), t.appType === y.enum.GAME && !n && /* @__PURE__ */ e.createElement(
      P,
      {
        baseItem: t,
        itemType: f.enum.APP,
        appType: y.enum.DLC,
        language: i,
        withWrapper: (L) => /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.dlcStore.heading" }, "Expansions")), L),
        noItemMessage: /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.inAppStore.noItem" }, "Looks like there are not any items for this game yet.")
      }
    ), !n && /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.inAppStore.heading" }, "Game Store")), /* @__PURE__ */ e.createElement(
      P,
      {
        baseItem: t,
        itemType: f.enum.INGAMEITEM,
        language: i,
        noItemMessage: /* @__PURE__ */ e.createElement(l, { i18nKey: "AppDetailPage.inAppStore.noItem" }, "Looks like there are not any items for this game yet.")
      }
    ))));
  }
}
const Ge = T(
  ({ itemId: o, language: r, isPreviewMode: i }) => {
    var a;
    return /* @__PURE__ */ e.createElement(Z, { itemId: o, language: r, isPreviewMode: i, key: (a = p.getUserManager().state.user) == null ? void 0 : a.userId });
  },
  (o, r) => o.itemId !== r.itemId || r.language !== o.language
);
export {
  Y as AppDetailPageError,
  X as AppDetailPageLoadingScreen,
  Ge as default
};
