import { ItemImageTag as g } from "./accelbyte-widgets192.mjs";
import { OverrideCSS as y } from "./accelbyte-widgets78.mjs";
import { CurrencyType as f } from "./accelbyte-widgets185.mjs";
import { EcomPath as E } from "./accelbyte-widgets59.mjs";
import { ItemHelper as h } from "./accelbyte-widgets398.mjs";
import { PurchaseHelper as I } from "./accelbyte-widgets211.mjs";
import { RegionDataItemHelper as c } from "./accelbyte-widgets388.mjs";
import v from "./accelbyte-widgets261.mjs";
import p from "classnames";
import { isValid as D, isBefore as P } from "date-fns";
import e, { Fragment as C } from "react";
import { Trans as s } from "react-i18next";
import { ExtendedLink as b } from "./accelbyte-widgets549.mjs";
import { DiscountCountdownWidget as L } from "./accelbyte-widgets194.mjs";
import "./accelbyte-widgets550.mjs";
import { StoreGridItemLogic as N } from "./accelbyte-widgets551.mjs";
const S = ({ paymentOption: m }) => {
  const { currencySymbol: t, finalPrice: a, regionData: r, currencyType: i, originalPrice: n } = m, o = c.calculateDiscountPercentage(r);
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: p("paymentOption", i === f.enum.REAL ? "realCurrency" : "virtualCurrency"),
      key: m.regionData.currencyCode
    },
    /* @__PURE__ */ e.createElement("div", { className: "discountedPrice" }, t, " ", a),
    c.isDiscounted(r) && /* @__PURE__ */ e.createElement(C, null, /* @__PURE__ */ e.createElement("s", { className: "priceStrikethrough" }, /* @__PURE__ */ e.createElement("div", { className: "price" }, t, " ", n)), /* @__PURE__ */ e.createElement("div", { className: "discountLabel" }, "-", o, "%"))
  );
};
class B extends e.Component {
  constructor(t) {
    super(t), this.makePaymentOptionList = () => {
      const { item: a, currencyMap: r } = this.props;
      return I.makePaymentOptionList(a.regionData || [], r);
    }, this.renderPaymentUnavailable = () => {
      const { additionalAppInfo: a } = this.logic.state;
      if (a) {
        const r = new Date(a.releaseDate || "");
        if (D(r) && P(new Date(), r))
          return /* @__PURE__ */ e.createElement(s, { i18nKey: "CatalogPurchaseWidget.comingSoonDate" }, "Release on ", { releaseDate: r });
      }
      return /* @__PURE__ */ e.createElement(s, { i18nKey: "StoreGridItem.unavailable" }, "Unavailable");
    }, this.state = {}, this.logic = new N({
      item: t.item
    }), this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.makePaymentOptionList().length <= 0 && this.logic.requestAdditionalAppInfo();
  }
  render() {
    const { item: t, currencyMap: a, disableHref: r } = this.props, i = this.makePaymentOptionList(), n = h.getFilteredImageUrlByTag(t.images, g.productCover) || v, o = c.isFree(t.regionData || []), d = r ? "javascript:void(0)" : E.getItemDetailRoute(t);
    return /* @__PURE__ */ e.createElement(b, { className: "storeGridItem", to: d, isExternal: r }, /* @__PURE__ */ e.createElement(
      "div",
      {
        className: "imageContainer",
        style: {
          backgroundImage: n ? `linear-gradient(180deg, rgba(0, 0, 0, 0.53) 9.44%, rgba(44, 61, 71, 0) 46.17%), url('${n}')` : void 0
        }
      },
      /* @__PURE__ */ e.createElement("div", { className: "discountCountdownWrapper" }, /* @__PURE__ */ e.createElement(L, { item: t, currencyMap: a }))
    ), /* @__PURE__ */ e.createElement("div", { className: p("title", y.TITLE_FONT) }, t.title), /* @__PURE__ */ e.createElement("div", { className: "paymentOptions" }, i.length > 0 && /* @__PURE__ */ e.createElement(e.Fragment, null, o && /* @__PURE__ */ e.createElement(s, { i18nKey: "StoreGridItem.freeItem" }, "FREE"), !o && i.map((l, u) => /* @__PURE__ */ e.createElement(S, { key: `${l.regionData.currencyCode}-${u}`, paymentOption: l }))), i.length === 0 && this.renderPaymentUnavailable()));
  }
}
export {
  B as StoreGridItem
};
