import { CommonError as g } from "./accelbyte-widgets124.mjs";
import { Loading as d, LoadingSize as y } from "./accelbyte-widgets136.mjs";
import I from "./accelbyte-widgets210.mjs";
import { Ctx as S } from "./accelbyte-widgets33.mjs";
import e from "react";
import { Trans as l } from "react-i18next";
import { StoreGridItem as E } from "./accelbyte-widgets416.mjs";
import "./accelbyte-widgets419.mjs";
import { InAppStoreLogic as f } from "./accelbyte-widgets420.mjs";
import { mockCurrencyMap as w, mockStoreItem as b } from "./accelbyte-widgets209.mjs";
class A extends e.Component {
  constructor(t) {
    super(t), this.initialShownItem = 8, t.initialShownItem && (this.initialShownItem = t.initialShownItem), this.logic = new f({
      baseItem: t.baseItem,
      itemType: t.itemType,
      appType: t.appType,
      country: t.country,
      language: t.language
    }), this.logic.subscribe(() => this.setState({})), this.state = {
      open: !1
    };
  }
  componentDidMount() {
    this.props.isPreviewMode || this.logic.init();
  }
  renderContent() {
    const { noItemMessage: t, loadingMessage: i, isPreviewMode: o } = this.props, { items: p, isFetching: u, error: a, currencyMap: h } = this.logic.state, { open: m } = this.state, n = o ? b.data : p, s = o ? w() : h;
    return /* @__PURE__ */ e.createElement("div", { className: "inAppStore" }, /* @__PURE__ */ e.createElement("div", { className: "inGameItemData" }, u ? /* @__PURE__ */ e.createElement(d, { className: y.medium }, i) : /* @__PURE__ */ e.createElement(e.Fragment, null, a && /* @__PURE__ */ e.createElement("div", { className: "errorContainer" }, /* @__PURE__ */ e.createElement(g, { error: a })), n && n.length === 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, t, !t && /* @__PURE__ */ e.createElement(l, { i18nKey: "InAppStore.grid.empty" }, "No Items Available")), /* @__PURE__ */ e.createElement("div", { className: "inGameItemGrid list" }, n && s && (m ? n : n.slice(0, this.initialShownItem)).map((c) => /* @__PURE__ */ e.createElement(E, { key: c.itemId, item: c, currencyMap: s }))))), n && n.length > this.initialShownItem && !m && /* @__PURE__ */ e.createElement("div", { className: "showMoreButton" }, /* @__PURE__ */ e.createElement("button", { className: "btn btn-primary", type: "button", onClick: () => this.setState({ open: !0 }) }, /* @__PURE__ */ e.createElement(l, { i18nKey: "InAppStore.showAllButton" }, "Show All"))));
  }
  render() {
    const { withWrapper: t } = this.props, { items: i, error: o } = this.logic.state;
    return t ? /* @__PURE__ */ e.createElement(e.Fragment, null, (i && i.length > 0 || o) && t(this.renderContent())) : /* @__PURE__ */ e.createElement(e.Fragment, null, this.renderContent());
  }
}
const D = I(
  (r) => {
    const t = S.getAppState();
    return /* @__PURE__ */ e.createElement(A, { country: (t.getUser() || { country: void 0 }).country, ...r });
  },
  (r, t) => r.baseItem !== t.baseItem || r.country !== t.country || r.itemType !== t.itemType
);
export {
  A as InAppStore,
  D as default
};
