import { a as Ctx, a7 as ItemType, a2 as EcomPath, F as FeUtils, t, L as Loading, w as LoadingSize, T as Trans, i as CommonError } from "./index.js";
import { P as Pagination } from "./Pagination.js";
import { w as withPropsGuard } from "./WithPropsGuard.js";
import { I as ItemListingAppManager, S as SkeletonGameCards } from "./StorePage.js";
import React__default from "react";
import { H as HelmetExport } from "./Helmet.js";
import { S as StoreGridItem } from "./ItemDetailPurchaseAlert.js";
import "./validator.js";
import "./dateFns.js";
import "./reactPlayer.js";
import "react-router-dom";
import "./reactSlick.js";
import "./CommonError.js";
import "./starBgGradient.js";
import "./CommonError2.js";
import "./Tabs.js";
import "./NavItemPlaceholder.js";
import "./AppDetailPage.js";
import "./ItemHelper.js";
import "./PlatformRequirements.js";
import "./default-item-image.js";
import "./SuccessFlatIcon.js";
import "./WarningIcon.js";
import "./PendingOrdersAppManager.js";
import "./PaymentStatusDialog.js";
import "./Radio.js";
var BundleStore$2 = "";
class BundleStore extends React__default.Component {
  constructor(props) {
    super(props);
    this.appStoreLogic = new ItemListingAppManager(Ctx.getAppState().getSdk());
    this.appStoreLogic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    const { page, pageSize, country, language } = this.props;
    this.appStoreLogic.getItemsByCriteria({ page, pageSize, country, language, itemType: ItemType.enum.BUNDLE });
    this.appStoreLogic.getCurrencyMap();
  }
  renderBundleItems() {
    const { platformItemsList, currencyMap } = this.appStoreLogic.state;
    return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("div", {
      className: "bundlesList"
    }, !currencyMap && /* @__PURE__ */ React__default.createElement(SkeletonGameCards, {
      numberOfCards: platformItemsList == null ? void 0 : platformItemsList.data.length
    }), !!platformItemsList && currencyMap && platformItemsList.data.map((bundle) => /* @__PURE__ */ React__default.createElement(StoreGridItem, {
      key: bundle.itemId,
      item: bundle,
      currencyMap
    }))));
  }
  renderGamePagination() {
    const { platformItemsList } = this.appStoreLogic.state;
    if (!platformItemsList)
      return;
    const { paging } = platformItemsList;
    const hasNext = !!(paging == null ? void 0 : paging.next);
    const hasPrev = !!(paging == null ? void 0 : paging.previous);
    const currentPage = this.props.page;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: "pagination"
    }, /* @__PURE__ */ React__default.createElement(Pagination, {
      next: hasNext && EcomPath.BundleList.withSearchParams({ page: currentPage + 1 }),
      prev: hasPrev && EcomPath.BundleList.withSearchParams({ page: currentPage - 1 })
    }));
  }
  render() {
    const { error, isFetching, platformItemsList } = this.appStoreLogic.state;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: "storeContainer"
    }, /* @__PURE__ */ React__default.createElement(HelmetExport, null, /* @__PURE__ */ React__default.createElement("title", null, FeUtils.makeTitleWithAppName(t("BundleStore.title")))), isFetching && /* @__PURE__ */ React__default.createElement(Loading, {
      className: LoadingSize.medium
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "InitialUserFetchPage.notice"
    })), !isFetching && error && /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(CommonError, {
      error
    })), !isFetching && platformItemsList && this.renderBundleItems(), !isFetching && platformItemsList && this.renderGamePagination());
  }
}
const BundleStoreWithPropsGuard = withPropsGuard(BundleStore, (prevProps, nextProps) => {
  return prevProps.country !== nextProps.country;
});
var BundleStore$1 = withPropsGuard(({ page, pageSize, language }) => {
  const user = Ctx.getAppState().getUser();
  const country = user && user.country || void 0;
  return /* @__PURE__ */ React__default.createElement(BundleStoreWithPropsGuard, {
    page,
    pageSize,
    country,
    language
  });
}, (prevProps, nextProps) => nextProps.page !== prevProps.page || nextProps.language !== prevProps.language);
export { BundleStore, BundleStore$1 as default };
