import { Breadcrumbs as L } from "./accelbyte-widgets190.mjs";
import { CommonError as b } from "./accelbyte-widgets204.mjs";
import { Lightbox as v } from "./accelbyte-widgets191.mjs";
import { Loading as D, LoadingSize as G } from "./accelbyte-widgets136.mjs";
import C from "./accelbyte-widgets210.mjs";
import { ItemHelper as y } from "./accelbyte-widgets192.mjs";
import { gaSendErrorEvent as S } from "./accelbyte-widgets145.mjs";
import { Ctx as d } from "./accelbyte-widgets33.mjs";
import { EcommerceErrorCode as f } from "./accelbyte-widgets185.mjs";
import { EcomPath as p } from "./accelbyte-widgets59.mjs";
import { ErrorPath as A } from "./accelbyte-widgets69.mjs";
import { GlobalPath as N } from "./accelbyte-widgets104.mjs";
import { ErrorHelper as E } from "./accelbyte-widgets120.mjs";
import { PageTitleUtils as x } from "./accelbyte-widgets188.mjs";
import { DesktopChecker as k } from "@accelbyte/sdk";
import e from "react";
import { Helmet as O } from "react-helmet";
import { Trans as l } from "react-i18next";
import { Link as g } from "react-router-dom";
import { DiscountCountdownWidget as T } from "./accelbyte-widgets194.mjs";
import { AppDetailGallery as K } from "./accelbyte-widgets195.mjs";
import { CatalogItemBanner as M } from "./accelbyte-widgets196.mjs";
import _ from "./accelbyte-widgets197.mjs";
import { CatalogPurchaseWidget as w } from "./accelbyte-widgets198.mjs";
import U from "./accelbyte-widgets199.mjs";
import { InAppStore as F } from "./accelbyte-widgets212.mjs";
import "./accelbyte-widgets201.mjs";
import { ItemDetailPurchaseAlert as R } from "./accelbyte-widgets202.mjs";
import "./accelbyte-widgets213.mjs";
import { InGameItemDetailPageLogic as W } from "./accelbyte-widgets225.mjs";
const q = () => /* @__PURE__ */ e.createElement(D, { className: G.tall }, /* @__PURE__ */ e.createElement(l, { i18nKey: "InitialUserFetchPage.notice" })), B = ({ error: i }) => {
  const r = () => i && E.extractServiceErrorCode(i) === f.PRODUCT_KEY_NOT_AVAILABLE ? /* @__PURE__ */ e.createElement(l, { i18nKey: "GameDetailViewPage.item.productKeyNotAvailable" }, "This product key is no longer available") : /* @__PURE__ */ e.createElement(b, { error: i });
  return /* @__PURE__ */ e.createElement("div", { className: "error" }, r());
};
class H extends e.Component {
  constructor(r) {
    super(r), this.openLightbox = (m) => {
      this.setState({ isLightboxOpen: !0, selectedImagePosition: m });
    }, this.closeLightbox = () => {
      this.setState({ isLightboxOpen: !1 });
    };
    const { itemId: a, country: n, language: t, user: o } = r;
    this.logic = new W({ itemId: a, country: n, language: t, user: o }), this.logic.subscribe(() => this.setState({})), this.state = {
      isLightboxOpen: !1,
      selectedImagePosition: 0
    };
  }
  componentDidMount() {
    this.logic.init();
  }
  render() {
    const r = d.getAppState().isSingleGame(), { user: a } = this.props, { isFetching: n, inGameItem: t, error: o, baseApp: m, itemPublishingContent: h } = this.logic.state;
    o && E.extractServiceErrorCode(o) === f.ITEM_NOT_FOUND && S({
      eventCategory: A.Error404.makePath(),
      eventLabel: E.errorToString(o)
    });
    const { purchaseLogic: s } = this.logic, u = s && s.state.currencyMap, { isLightboxOpen: I, selectedImagePosition: P } = this.state, c = y.getMedia(t, h);
    return /* @__PURE__ */ e.createElement("main", { className: "itemDetailPage" }, /* @__PURE__ */ e.createElement(
      R,
      {
        purchaseLogic: s,
        user: a,
        isFetching: n
      }
    ), /* @__PURE__ */ e.createElement(O, null, t && /* @__PURE__ */ e.createElement("title", null, x.getPageTitle(d.getAppState().state.discovery || null, t.title, t.title))), n && /* @__PURE__ */ e.createElement(q, null), o && /* @__PURE__ */ e.createElement(B, { error: o }), t && m && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(M, { item: t, itemPublishingContent: h }, /* @__PURE__ */ e.createElement(L, null, /* @__PURE__ */ e.createElement(g, { to: p.GameList.makePath() }, /* @__PURE__ */ e.createElement(l, { i18nKey: "Navigation.links.games" }, "Games")), /* @__PURE__ */ e.createElement(
      g,
      {
        to: p.GameItem.makePath({
          itemId: m.itemId
        })
      },
      m.title
    ), t.title)), c && /* @__PURE__ */ e.createElement(K, { itemMedias: c, openLightbox: this.openLightbox }), I && c && /* @__PURE__ */ e.createElement(
      v,
      {
        itemMedias: c,
        isOpen: I,
        onClose: this.closeLightbox,
        selectedPosition: P
      }
    ), /* @__PURE__ */ e.createElement("div", { className: "itemDetailContent container" }, /* @__PURE__ */ e.createElement("div", { className: "description" }, /* @__PURE__ */ e.createElement(_, { item: t })), /* @__PURE__ */ e.createElement("div", { className: "detailWidget" }, /* @__PURE__ */ e.createElement(U, { item: t }, u && /* @__PURE__ */ e.createElement(T, { item: t, currencyMap: u, position: "right", showDetail: !0 })), /* @__PURE__ */ e.createElement("div", { className: "protruded" }, /* @__PURE__ */ e.createElement(w, { item: t, purchaseLogic: s })), /* @__PURE__ */ e.createElement("div", { className: "requiredApp" }, /* @__PURE__ */ e.createElement(l, { i18nKey: "InGameItemDetailPage.requiredAppNotice" }, "Required Game"), /* @__PURE__ */ e.createElement(
      g,
      {
        to: k.isDesktopApp() && r ? N.Game.link : p.GameItem.makePath({
          itemId: m.itemId
        })
      },
      m.title
    )))), /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(l, { i18nKey: "InGameItemDetailPage.inAppStore.heading" }, "Related Items")), /* @__PURE__ */ e.createElement(
      F,
      {
        baseItem: t,
        language: this.props.language,
        noItemMessage: /* @__PURE__ */ e.createElement("div", { className: "noItem" }, /* @__PURE__ */ e.createElement(l, { i18nKey: "InGameItemDetailPage.inAppStore.noItem" }, "Looks like there are no related items yet."))
      }
    ))));
  }
}
const be = C(
  ({ itemId: i, language: r }) => {
    const a = d.getAppState().getUser() || void 0, n = a && a.country || void 0;
    return /* @__PURE__ */ e.createElement(H, { itemId: i, country: n, user: a, language: r });
  },
  (i, r) => i.itemId !== r.itemId || r.language !== i.language
);
export {
  H as InGameItemDetailPage,
  B as ItemDetailPageError,
  q as ItemDetailPageLoadingScreen,
  be as default
};
