import { a as Ctx, a7 as ItemType, a2 as EcomPath, F as FeUtils, t, as as LoadingPage, 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 AppStore$2 = "";
class AppStore extends React__default.Component {
  constructor(props) {
    super(props);
    this.logic = new ItemListingAppManager(Ctx.getAppState().getSdk());
    this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    const { page, pageSize, country, language, plan } = this.props;
    this.logic.getItemsByCriteria({
      page,
      pageSize,
      country,
      language,
      plan,
      itemType: ItemType.enum.APP
    });
    this.logic.getCurrencyMap();
  }
  renderGameItems() {
    const { platformItemsList, currencyMap } = this.logic.state;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: "appsList"
    }, !currencyMap && /* @__PURE__ */ React__default.createElement(SkeletonGameCards, {
      numberOfCards: platformItemsList == null ? void 0 : platformItemsList.data.length
    }), !!platformItemsList && currencyMap && platformItemsList.data.map((gameItem) => /* @__PURE__ */ React__default.createElement(StoreGridItem, {
      key: gameItem.itemId,
      item: gameItem,
      currencyMap
    })));
  }
  renderGamePagination() {
    const { platformItemsList } = this.logic.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.GameList.withSearchParams({
        page: currentPage + 1
      }),
      prev: hasPrev && EcomPath.GameList.withSearchParams({
        page: currentPage - 1
      })
    }));
  }
  render() {
    const { error, isFetching, platformItemsList } = this.logic.state;
    return /* @__PURE__ */ React__default.createElement("div", {
      className: "storeContainer"
    }, /* @__PURE__ */ React__default.createElement(HelmetExport, null, /* @__PURE__ */ React__default.createElement("title", null, FeUtils.makeTitleWithAppName(t("AppStore.title")))), isFetching && /* @__PURE__ */ React__default.createElement(LoadingPage, null), !isFetching && error && /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(CommonError, {
      error
    })), !isFetching && platformItemsList && this.renderGameItems(), !isFetching && platformItemsList && this.renderGamePagination());
  }
}
const AppStoreWithPropsGuard = withPropsGuard(AppStore, (prevProps, nextProps) => {
  return prevProps.country !== nextProps.country;
});
var AppStore$1 = withPropsGuard(({ page, pageSize, language, plan }) => {
  const user = Ctx.getAppState().getUser();
  const country = user && user.country || void 0;
  return /* @__PURE__ */ React__default.createElement(AppStoreWithPropsGuard, {
    page,
    pageSize,
    country,
    language,
    plan
  });
}, (prevProps, nextProps) => nextProps.page !== prevProps.page || nextProps.language !== prevProps.language || nextProps.plan !== prevProps.plan);
export { AppStore, AppStore$1 as default };
