import { CommonError as g } from "./accelbyte-widgets124.mjs";
import { BackLinkIcon as N } from "./accelbyte-widgets126.mjs";
import { Loading as f } from "./accelbyte-widgets136.mjs";
import { OrderLogic as P } from "./accelbyte-widgets260.mjs";
import { Ctx as I } from "./accelbyte-widgets33.mjs";
import { CurrencyType as D } from "./accelbyte-widgets185.mjs";
import { AccPath as O } from "./accelbyte-widgets34.mjs";
import { FeUtils as h } from "./accelbyte-widgets45.mjs";
import { GameHelper as T } from "./accelbyte-widgets205.mjs";
import { PurchaseHelper as s } from "./accelbyte-widgets211.mjs";
import { UrlUtils as u } from "./accelbyte-widgets90.mjs";
import H from "./accelbyte-widgets261.mjs";
import e from "react";
import { Trans as r } from "react-i18next";
import { Link as v } from "react-router-dom";
import { AccountMainSection as x, AccountMainSectionHeader as C, AccountMainSectionBody as b } from "./accelbyte-widgets122.mjs";
import S from "./accelbyte-widgets262.mjs";
class J extends e.Component {
  constructor(i) {
    var m;
    super(i), this.getItemImage = (t) => {
      const { thumbnailUrl: n } = t;
      if (n && u.isValidUrl(n))
        return n;
      const a = T.getGameIconImage(t);
      return a && u.isValidUrl(a) ? a : H;
    }, this.renderOrderItem = (t, n, a) => /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "orderItemContainer" }, /* @__PURE__ */ e.createElement("div", { className: "tableHead" }, /* @__PURE__ */ e.createElement("p", { className: "itemName" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.item" }, "Item")), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.price" }, "Price")), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.quantity" }, "Quantity")), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.subtotal" }, "Subtotal"))), /* @__PURE__ */ e.createElement("div", { className: "divider top" }), n.regionDataItem && /* @__PURE__ */ e.createElement("div", { className: "itemInfoContainer" }, /* @__PURE__ */ e.createElement("div", { className: "itemContainer" }, /* @__PURE__ */ e.createElement("img", { className: "itemImage", src: this.getItemImage(a), alt: a.title, loading: "lazy" }), /* @__PURE__ */ e.createElement("p", { className: "itemName" }, a.title)), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, `${t.currency.currencySymbol} ${s.calculateIntegerPrice(
      (t.subtotalPrice ? t.subtotalPrice : 0) / t.quantity,
      t.currency
    )}`), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, t.quantity), /* @__PURE__ */ e.createElement("p", { className: "itemText" }, `${t.currency.currencySymbol} ${s.calculateIntegerPrice(
      t.subtotalPrice ? t.subtotalPrice : 0,
      t.currency
    )}`))), /* @__PURE__ */ e.createElement("div", { className: "divider bottom" }), this.renderTotalOrder(t)), this.renderTotalOrder = (t) => {
      const {
        status: n,
        currency: { currencySymbol: a },
        totalPrice: d = 0,
        totalTax: y = 0
      } = t, E = s.calculateIntegerPrice(y, t.currency), p = s.calculateIntegerPrice(d, t.currency), o = t.currency.currencyType === D.enum.REAL;
      return /* @__PURE__ */ e.createElement("div", { className: "totalOrderContainer" }, /* @__PURE__ */ e.createElement("div", { className: "infoNameColumn" }, o && /* @__PURE__ */ e.createElement("p", { className: "infoText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.tax" }, "Tax")), /* @__PURE__ */ e.createElement("p", { className: "infoText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.total" }, "Total")), /* @__PURE__ */ e.createElement("p", { className: "infoText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.status" }, "Status"))), /* @__PURE__ */ e.createElement("div", { className: "emptyDividerColumn" }), /* @__PURE__ */ e.createElement("div", { className: "infoAmountColumn" }, o && /* @__PURE__ */ e.createElement("p", { className: "infoAmount" }, a, " ", E), /* @__PURE__ */ e.createElement("p", { className: "infoAmount" }, a, " ", p), /* @__PURE__ */ e.createElement("p", { className: "infoAmount" }, n)));
    }, this.renderOrderHistoryDetail = (t, n) => {
      const a = h.formatDate(t.createdTime, { type: "dynamic", format: "LLLL" });
      return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "orderInfoContainer" }, /* @__PURE__ */ e.createElement("p", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.orderDate" }, "Order date")), /* @__PURE__ */ e.createElement("p", null, a)), /* @__PURE__ */ e.createElement("div", { className: "orderInfoContainer" }, /* @__PURE__ */ e.createElement("p", { className: "infoTitle" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.orderID" }, "Order No")), /* @__PURE__ */ e.createElement("p", null, t.orderNo)), !t.itemSnapshot && /* @__PURE__ */ e.createElement("div", { className: "noData" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.noItemDataFound" }, "Item data not found")), t.itemSnapshot && this.renderOrderItem(t, t.itemSnapshot, n));
    };
    const { orderNo: c } = this.props, l = ((m = I.getAppState().getUser()) == null ? void 0 : m.userId) || "";
    this.logic = new P({ userId: l, orderNo: c }), this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.logic.init();
  }
  render() {
    const { isFetching: i, order: c, item: l, error: m } = this.logic.state;
    return /* @__PURE__ */ e.createElement(x, { className: S.orderHistoryDetailPage }, /* @__PURE__ */ e.createElement(C, null, /* @__PURE__ */ e.createElement("span", { className: "navigationContainer" }, /* @__PURE__ */ e.createElement(v, { to: O.OrderHistory.makePath() }, /* @__PURE__ */ e.createElement(N, null))), /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryDetailPage.title" }, "Order History")), /* @__PURE__ */ e.createElement(b, null, i && /* @__PURE__ */ e.createElement(f, { className: "loading" }), !i && m && /* @__PURE__ */ e.createElement("div", { className: "errorContainer" }, /* @__PURE__ */ e.createElement(g, { error: m })), !i && c && l && this.renderOrderHistoryDetail(c, l)));
  }
}
export {
  J as default
};
