import { U as UrlUtils, aa as GameHelper, T as Trans, ab as PurchaseHelper, a6 as CurrencyType, F as FeUtils, a as Ctx, g as AccPath, L as Loading, i as CommonError } from "./index.js";
import { B as BackLinkIcon } from "./BackLinkIcon.js";
import { O as OrderLogic } from "./OrderLogic.js";
import { d as defaultItemImage } from "./default-item-image.js";
import React__default from "react";
import { Link } from "react-router-dom";
import { A as AccountMainSection, b as AccountMainSectionHeader, a as AccountMainSectionBody } from "./AccountMainSection.js";
import "./validator.js";
import "./dateFns.js";
import "./reactPlayer.js";
import "./reactSlick.js";
import "./PendingOrdersAppManager.js";
const orderHistoryDetailPage = "orderHistoryDetailPage _orderHistoryDetailPage_660de";
var styles = {
  orderHistoryDetailPage
};
class OrderHistoryDetailPage extends React__default.Component {
  constructor(props) {
    var _a;
    super(props);
    this.getItemImage = (itemInfo) => {
      const { thumbnailUrl } = itemInfo;
      if (thumbnailUrl && UrlUtils.isValidUrl(thumbnailUrl))
        return thumbnailUrl;
      const iconImage = GameHelper.getGameIconImage(itemInfo);
      if (iconImage && UrlUtils.isValidUrl(iconImage))
        return iconImage;
      return defaultItemImage;
    };
    this.renderOrderItem = (order, itemSnapshot, itemInfo) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("div", {
      className: "orderItemContainer"
    }, /* @__PURE__ */ React__default.createElement("div", {
      className: "tableHead"
    }, /* @__PURE__ */ React__default.createElement("p", {
      className: "itemName"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "OrderHistoryDetailPage.item"
    }, "Item")), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "OrderHistoryDetailPage.price"
    }, "Price")), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "OrderHistoryDetailPage.quantity"
    }, "Quantity")), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "OrderHistoryDetailPage.subtotal"
    }, "Subtotal"))), /* @__PURE__ */ React__default.createElement("div", {
      className: "divider top"
    }), itemSnapshot.regionDataItem && /* @__PURE__ */ React__default.createElement("div", {
      className: "itemInfoContainer"
    }, /* @__PURE__ */ React__default.createElement("div", {
      className: "itemContainer"
    }, /* @__PURE__ */ React__default.createElement("img", {
      className: "itemImage",
      src: this.getItemImage(itemInfo),
      alt: itemInfo.title,
      loading: "lazy"
    }), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemName"
    }, itemInfo.title)), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, `${order.currency.currencySymbol} ${PurchaseHelper.calculateIntegerPrice((order.subtotalPrice ? order.subtotalPrice : 0) / order.quantity, order.currency)}`), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, order.quantity), /* @__PURE__ */ React__default.createElement("p", {
      className: "itemText"
    }, `${order.currency.currencySymbol} ${PurchaseHelper.calculateIntegerPrice(order.subtotalPrice ? order.subtotalPrice : 0, order.currency)}`))), /* @__PURE__ */ React__default.createElement("div", {
      className: "divider bottom"
    }), this.renderTotalOrder(order));
    this.renderTotalOrder = (order) => {
      const {
        status,
        currency: { currencySymbol },
        totalPrice = 0,
        totalTax = 0
      } = order;
      const tax = PurchaseHelper.calculateIntegerPrice(totalTax, order.currency);
      const calculatedTotalPrice = PurchaseHelper.calculateIntegerPrice(totalPrice, order.currency);
      const showTax = order.currency.currencyType === CurrencyType.enum.REAL;
      return /* @__PURE__ */ React__default.createElement("div", {
        className: "totalOrderContainer"
      }, /* @__PURE__ */ React__default.createElement("div", {
        className: "infoNameColumn"
      }, showTax && /* @__PURE__ */ React__default.createElement("p", {
        className: "infoText"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.tax"
      }, "Tax")), /* @__PURE__ */ React__default.createElement("p", {
        className: "infoText"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.total"
      }, "Total")), /* @__PURE__ */ React__default.createElement("p", {
        className: "infoText"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.status"
      }, "Status"))), /* @__PURE__ */ React__default.createElement("div", {
        className: "emptyDividerColumn"
      }), /* @__PURE__ */ React__default.createElement("div", {
        className: "infoAmountColumn"
      }, showTax && /* @__PURE__ */ React__default.createElement("p", {
        className: "infoAmount"
      }, currencySymbol, " ", tax), /* @__PURE__ */ React__default.createElement("p", {
        className: "infoAmount"
      }, currencySymbol, " ", calculatedTotalPrice), /* @__PURE__ */ React__default.createElement("p", {
        className: "infoAmount"
      }, status)));
    };
    this.renderOrderHistoryDetail = (order, itemInfo) => {
      const createdDate = FeUtils.formatDate(order.createdTime, "LLLL");
      return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("div", {
        className: "orderInfoContainer"
      }, /* @__PURE__ */ React__default.createElement("p", {
        className: "infoTitle"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.orderDate"
      }, "Order date")), /* @__PURE__ */ React__default.createElement("p", null, createdDate)), /* @__PURE__ */ React__default.createElement("div", {
        className: "orderInfoContainer"
      }, /* @__PURE__ */ React__default.createElement("p", {
        className: "infoTitle"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.orderID"
      }, "Order No")), /* @__PURE__ */ React__default.createElement("p", null, order.orderNo)), !order.itemSnapshot && /* @__PURE__ */ React__default.createElement("div", {
        className: "noData"
      }, /* @__PURE__ */ React__default.createElement(Trans, {
        i18nKey: "OrderHistoryDetailPage.noItemDataFound"
      }, "Item data not found")), order.itemSnapshot && this.renderOrderItem(order, order.itemSnapshot, itemInfo));
    };
    const { orderNo } = this.props;
    const userId = ((_a = Ctx.getAppState().getUser()) == null ? void 0 : _a.userId) || "";
    this.logic = new OrderLogic({ userId, orderNo });
    this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.logic.init();
  }
  render() {
    const { isFetching, order, item, error } = this.logic.state;
    return /* @__PURE__ */ React__default.createElement(AccountMainSection, {
      className: styles.orderHistoryDetailPage
    }, /* @__PURE__ */ React__default.createElement(AccountMainSectionHeader, null, /* @__PURE__ */ React__default.createElement("span", {
      className: "navigationContainer"
    }, /* @__PURE__ */ React__default.createElement(Link, {
      to: AccPath.OrderHistory.makePath()
    }, /* @__PURE__ */ React__default.createElement(BackLinkIcon, null))), /* @__PURE__ */ React__default.createElement(Trans, {
      i18nKey: "OrderHistoryDetailPage.title"
    }, "Order History")), /* @__PURE__ */ React__default.createElement(AccountMainSectionBody, null, isFetching && /* @__PURE__ */ React__default.createElement(Loading, {
      className: "loading"
    }), !isFetching && error && /* @__PURE__ */ React__default.createElement("div", {
      className: "errorContainer"
    }, /* @__PURE__ */ React__default.createElement(CommonError, {
      error
    })), !isFetching && order && item && this.renderOrderHistoryDetail(order, item)));
  }
}
export { OrderHistoryDetailPage as default };
