import { O as S, I as L, C as T, B as G, c as y, A as M, L as k, e as I, a as K, b as x, D as W } from "./ItemDetailPurchaseAlert-3cdb1ea7.mjs";
import { C as U } from "./CommonError-0ae83068.mjs";
import { T as r, C as B, a as f, w as O, av as F, k as D, l as V, y as b, G as R, ag as _, K as j, F as q, ab as H, ad as P, au as N, aw as $, ax as z } from "./index-162fd1aa.mjs";
import { w as J } from "./WithPropsGuard-9dd19ecc.mjs";
import { I as Q } from "./ItemHelper-37a12c2c.mjs";
import e from "react";
import { H as X } from "./Helmet-ed6d5573.mjs";
import { Link as Y } from "react-router-dom";
import { P as w } from "./PlatformRequirements-fc8525b3.mjs";
import { e as Z } from "./MockVars-1cf2eb0a.mjs";
const ee = (l) => {
  const { additionalAppInfo: t } = l, { platforms: n, releaseDate: i, primaryGenre: o, genres: m, developer: p, publisher: s, websiteUrl: c, forumUrl: g } = t;
  return !n && !i && !m && !p && !s && !c && !g ? null : /* @__PURE__ */ e.createElement("div", { className: "gameDetailInfo" }, /* @__PURE__ */ e.createElement("ul", null, n && n.length > 0 && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.platform" }, "Platform")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, n.join(", "))), i && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.releaseDate" }, "Release Date")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.releaseDateValue" }, { releaseDate: new Date(i) }))), o && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.primaryGenre" }, "Primary Genre")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, o)), m && m.length > 0 && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.genre" }, "Genre")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, m.join(", "))), p && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.developer" }, "Developer")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, p)), s && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.publisher" }, "Publisher")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, s)), c && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.websiteUrl" }, "Website URL")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, c)), g && /* @__PURE__ */ e.createElement("li", { className: "infoWrapper" }, /* @__PURE__ */ e.createElement("h2", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "GameDetailViewPage.detailInfo.forumUrl" }, "Forum URL")), /* @__PURE__ */ e.createElement("p", { className: "infoContent" }, g))));
};
class te extends B {
  constructor(t) {
    super(), this.props = t, this.state = {
      isFetching: !1,
      appItem: null,
      additionalAppInfo: null,
      itemPublishingContent: null,
      error: null,
      itemPublishingContentError: null
    }, this.sdk = f.getAppState().getSdk();
  }
  async init() {
    try {
      if (this.state.isFetching)
        return;
      await this.setState({
        isFetching: !0,
        error: null,
        appItem: null,
        additionalAppInfo: null
      });
      const { itemId: t, country: n, language: i, user: o } = this.props, [
        { response: m, error: p },
        { response: s, error: c },
        { response: g, error: u }
      ] = await Promise.all([
        this.sdk.Platform.Item().getItemsByItemIdLocale({
          itemId: t,
          queryParams: {
            region: n,
            language: i
          }
        }),
        this.sdk.Platform.Item().getAppInfoByItemId({ itemId: t }),
        { response: null, error: null }
      ]);
      if (p)
        throw p;
      if (c)
        throw c;
      if (s && m) {
        const d = m.data, a = this.purchaseLogic = new S(this.sdk, {
          item: d,
          userId: O.safeParse(o).success ? o == null ? void 0 : o.userId : null
        });
        a.subscribe(() => this.setState({})), await a.init();
        const { fetchError: h } = a.state;
        if (h)
          throw h;
        await this.setState({
          appItem: d,
          additionalAppInfo: s.data
        });
      }
      u ? await this.setState({
        itemPublishingContentError: u
      }) : g && await this.setState({
        itemPublishingContent: g.data
      });
    } catch (t) {
      console.error(t), this.setState({ error: t });
    } finally {
      await this.setState({ isFetching: !1 });
    }
  }
}
const A = () => /* @__PURE__ */ e.createElement(F, { className: "mt-3 md:mt-7" }), C = ({ error: l }) => {
  const t = () => {
    switch (!0) {
      case l instanceof z:
      case l instanceof $:
        return /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.item.decodeError" }, "The game data from the server is invalid. Please refresh the page.");
      default:
        return /* @__PURE__ */ e.createElement(U, { error: l });
    }
  };
  return /* @__PURE__ */ e.createElement("div", { className: "error" }, t());
};
class ae extends e.Component {
  constructor(t) {
    super(t), this.openLightbox = (p) => {
      this.setState({ isLightboxOpen: !0, selectedImagePosition: p });
    }, this.closeLightbox = () => {
      this.setState({ isLightboxOpen: !1 });
    };
    const n = f.getUserManager().state.user || void 0, i = n == null ? void 0 : n.country, { itemId: o, language: m } = t;
    this.logic = new te({ itemId: o, country: i, user: n, language: m }), this.logic.subscribe(() => this.setState({})), this.state = {
      isLightboxOpen: !1,
      selectedImagePosition: 0
    };
  }
  componentDidMount() {
    this.props.isPreviewMode || (D.updateBackground(`url(${V})`), this.logic.init());
  }
  componentWillUnmount() {
    D.updateBackground(null);
  }
  render() {
    const t = f.getUserManager().state.user || void 0, { language: n, isPreviewMode: i } = this.props, { isLightboxOpen: o, selectedImagePosition: m } = this.state, { appItem: p, additionalAppInfo: s, itemPublishingContent: c, isFetching: g, error: u } = this.logic.state, { purchaseLogic: d } = this.logic, a = i ? Z : p, h = Q.getMedia(a, c), E = i ? i.isSingleGame : f.getAppState().isSingleGame();
    return u && b.extractServiceErrorCode(u) === R.ITEM_NOT_FOUND && _({ eventCategory: j.Error404.makePath(), eventLabel: b.errorToString(u) }), /* @__PURE__ */ e.createElement("div", { className: "itemDetailPage" }, /* @__PURE__ */ e.createElement(
      L,
      {
        purchaseLogic: d,
        user: t,
        isFetching: g,
        isPreviewMode: !!i
      }
    ), /* @__PURE__ */ e.createElement(X, null, a && /* @__PURE__ */ e.createElement("title", null, q.makeTitleWithAppName(a.title))), g && /* @__PURE__ */ e.createElement(A, null), u && /* @__PURE__ */ e.createElement(C, { error: u }), a && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(T, { item: a, itemPublishingContent: c, isPreviewMode: !!i }, !E && /* @__PURE__ */ e.createElement(G, null, /* @__PURE__ */ e.createElement(Y, { to: H.GameList.makePath() }, /* @__PURE__ */ e.createElement(r, { i18nKey: "Navigation.links.games" }, "Games")), a.title), E && /* @__PURE__ */ e.createElement(
      y,
      {
        item: a,
        itemPublishingContent: c,
        purchaseLogic: d,
        additionalAppInfo: s,
        isPreviewMode: !!i
      }
    )), h && !E && /* @__PURE__ */ e.createElement(M, { itemMedias: h, openLightbox: this.openLightbox }), o && h && !E && /* @__PURE__ */ e.createElement(
      k,
      {
        itemMedias: h,
        isOpen: o,
        onClose: this.closeLightbox,
        selectedPosition: m
      }
    ), !E && /* @__PURE__ */ e.createElement("div", { className: "availableBundleContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.availableBundles.heading" }, "Available Bundles")), /* @__PURE__ */ e.createElement(
      I,
      {
        baseItem: a,
        itemType: P.enum.BUNDLE,
        language: n,
        initialShownItem: 4,
        noItemMessage: /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.availableBundles.noItem" }, "Looks like there are no items for this game yet.")
      }
    )), !E && /* @__PURE__ */ e.createElement("div", { className: "itemDetailContent" }, /* @__PURE__ */ e.createElement("div", { className: "description" }, /* @__PURE__ */ e.createElement(K, { item: a }), s && /* @__PURE__ */ e.createElement(w, { className: "requirementsDesktop", additionalAppInfo: s })), /* @__PURE__ */ e.createElement("div", { className: "detailWidget" }, d && d.state.currencyMap && /* @__PURE__ */ e.createElement(x, { item: a }, /* @__PURE__ */ e.createElement(
      W,
      {
        item: a,
        currencyMap: d.state.currencyMap,
        position: "right",
        showDetail: !0
      }
    )), /* @__PURE__ */ e.createElement("div", { className: "protruded" }, /* @__PURE__ */ e.createElement(
      y,
      {
        item: a,
        itemPublishingContent: c,
        purchaseLogic: d,
        additionalAppInfo: s
      }
    )), s && /* @__PURE__ */ e.createElement(ee, { additionalAppInfo: s })), s && /* @__PURE__ */ e.createElement(w, { className: "requirementsMobile", additionalAppInfo: s })), a.appType === N.enum.GAME && !E && /* @__PURE__ */ e.createElement(
      I,
      {
        baseItem: a,
        itemType: P.enum.APP,
        appType: N.enum.DLC,
        language: n,
        withWrapper: (v) => /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.dlcStore.heading" }, "Expansions")), v),
        noItemMessage: /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.inAppStore.noItem" }, "Looks like there are not any items for this game yet.")
      }
    ), !E && /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.inAppStore.heading" }, "Game Store")), /* @__PURE__ */ e.createElement(
      I,
      {
        baseItem: a,
        itemType: P.enum.INGAMEITEM,
        language: n,
        noItemMessage: /* @__PURE__ */ e.createElement(r, { i18nKey: "AppDetailPage.inAppStore.noItem" }, "Looks like there are not any items for this game yet.")
      }
    ))));
  }
}
const ne = J(
  ({ itemId: l, language: t, isPreviewMode: n }) => {
    var i;
    return /* @__PURE__ */ e.createElement(ae, { itemId: l, language: t, isPreviewMode: n, key: (i = f.getUserManager().state.user) == null ? void 0 : i.userId });
  },
  (l, t) => l.itemId !== t.itemId || t.language !== l.language
), ue = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  AppDetailPageError: C,
  AppDetailPageLoadingScreen: A,
  default: ne
}, Symbol.toStringTag, { value: "Module" }));
export {
  te as A,
  A as a,
  C as b,
  ue as c
};
