import { Breadcrumbs as I } from "./accelbyte-widgets190.mjs";
import { Lightbox as C } from "./accelbyte-widgets191.mjs";
import { t as P } from "./accelbyte-widgets58.mjs";
import { ItemHelper as y } from "./accelbyte-widgets192.mjs";
import { gaSendErrorEvent as D } from "./accelbyte-widgets145.mjs";
import { Ctx as E } from "./accelbyte-widgets33.mjs";
import { EcommerceErrorCode as b, ItemType as L } from "./accelbyte-widgets185.mjs";
import { EcomPath as g } from "./accelbyte-widgets59.mjs";
import { ErrorPath as v } from "./accelbyte-widgets69.mjs";
import { ErrorHelper as h } from "./accelbyte-widgets120.mjs";
import { PageTitleUtils as x } from "./accelbyte-widgets188.mjs";
import e from "react";
import N from "react-helmet";
import { Trans as c } from "react-i18next";
import { Link as p } from "react-router-dom";
import "./accelbyte-widgets193.mjs";
import { DiscountCountdownWidget as S } from "./accelbyte-widgets194.mjs";
import { AppDetailGallery as A } from "./accelbyte-widgets195.mjs";
import { CatalogItemBanner as O } from "./accelbyte-widgets196.mjs";
import T from "./accelbyte-widgets197.mjs";
import { CatalogPurchaseWidget as w } from "./accelbyte-widgets198.mjs";
import K from "./accelbyte-widgets199.mjs";
import { RelatedProductKey as M } from "./accelbyte-widgets200.mjs";
import "./accelbyte-widgets201.mjs";
import { ItemDetailPageLoadingScreen as k, ItemDetailPageError as R } from "./accelbyte-widgets67.mjs";
import { ItemDetailPurchaseAlert as U } from "./accelbyte-widgets202.mjs";
import { CodeItemDetailPageLogic as W } from "./accelbyte-widgets203.mjs";
class _ extends e.Component {
  constructor(i) {
    super(i), this.openLightbox = (n) => {
      this.setState({ isLightboxOpen: !0, selectedImagePosition: n });
    }, this.closeLightbox = () => {
      this.setState({ isLightboxOpen: !1 });
    };
    const { itemId: a, country: t, language: r, user: o } = this.props;
    this.logic = new W({ itemId: a, country: t, language: r, user: o }), this.logic.subscribe(() => this.setState({})), this.state = {
      isLightboxOpen: !1,
      selectedImagePosition: 0
    };
  }
  async componentDidMount() {
    await this.initialize();
  }
  async componentDidUpdate(i) {
    (i.itemId !== this.props.itemId || i.language !== this.props.language) && await this.initialize();
  }
  async initialize() {
    this.logic.setProperties(this.props), await this.logic.init();
  }
  render() {
    const { user: i } = this.props, { isFetching: a, codeItem: t, error: r, baseApp: o, itemPublishingContent: n } = this.logic.state;
    r && h.extractServiceErrorCode(r) === b.ITEM_NOT_FOUND && D({ eventCategory: v.Error404.makePath(), eventLabel: h.errorToString(r) });
    const { purchaseLogic: l } = this.logic, d = l && l.state.currencyMap, { isLightboxOpen: u, selectedImagePosition: f } = this.state, s = y.getMedia(t, n);
    return /* @__PURE__ */ e.createElement("main", { className: "itemDetailPage" }, /* @__PURE__ */ e.createElement(
      U,
      {
        purchaseLogic: l,
        user: i,
        isFetching: a
      }
    ), /* @__PURE__ */ e.createElement(N, null, t && /* @__PURE__ */ e.createElement("title", null, x.getPageTitle(E.getAppState().state.discovery || null, t.title, t.title))), a && /* @__PURE__ */ e.createElement(k, null), r && /* @__PURE__ */ e.createElement(R, { error: r }), t && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(O, { item: t, itemPublishingContent: n }, /* @__PURE__ */ e.createElement(I, null, /* @__PURE__ */ e.createElement(p, { to: g.CodeList.makePath() }, /* @__PURE__ */ e.createElement(c, { i18nKey: "Navigation.links.productKeys" }, "Product Keys")), o && /* @__PURE__ */ e.createElement(p, { to: g.getItemDetailRoute(o) }, o.title), t.title)), s && /* @__PURE__ */ e.createElement(A, { itemMedias: s, openLightbox: this.openLightbox }), u && s && /* @__PURE__ */ e.createElement(
      C,
      {
        itemMedias: s,
        isOpen: u,
        onClose: this.closeLightbox,
        selectedPosition: f
      }
    ), /* @__PURE__ */ e.createElement("div", { className: "itemDetailContent" }, /* @__PURE__ */ e.createElement("div", { className: "description" }, /* @__PURE__ */ e.createElement(T, { item: t })), /* @__PURE__ */ e.createElement("div", { className: "detailWidget" }, /* @__PURE__ */ e.createElement(K, { item: t, tag: P("CodeItemDetailPage.tag") }, d && /* @__PURE__ */ e.createElement(S, { item: t, currencyMap: d, position: "right", showDetail: !0 })), /* @__PURE__ */ e.createElement("div", { className: "protruded" }, /* @__PURE__ */ e.createElement(w, { item: t, purchaseLogic: l })), o && /* @__PURE__ */ e.createElement("div", { className: "requiredApp" }, /* @__PURE__ */ e.createElement(c, { i18nKey: "CodeItemDetailPage.requiredAppNotice" }, "Required Game"), /* @__PURE__ */ e.createElement(p, { to: g.getItemDetailRoute(o) }, o.title)))), /* @__PURE__ */ e.createElement("div", { className: "storeContainer" }, /* @__PURE__ */ e.createElement("h2", null, /* @__PURE__ */ e.createElement(c, { i18nKey: "CodeItemDetailPage.inAppStore.heading" }, "Related Items")), /* @__PURE__ */ e.createElement(
      M,
      {
        baseItem: t,
        language: this.props.language,
        itemType: L.enum.CODE,
        noItemMessage: /* @__PURE__ */ e.createElement("div", { className: "noItem" }, /* @__PURE__ */ e.createElement(c, { i18nKey: "CodeItemDetailPage.inAppStore.noItem" }, "Looks like there are no related items yet."))
      }
    ))));
  }
}
const de = e.memo(
  (m) => {
    const { itemId: i, language: a } = m, t = E.getAppState().getUser() || void 0, r = t && t.country || void 0;
    return /* @__PURE__ */ e.createElement(_, { itemId: i, country: r, user: t, language: a });
  },
  (m, i) => m.itemId === i.itemId && i.language === m.language
);
export {
  de as default
};
